You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: beta/src/pages/reference/render.md
+26-23
Original file line number
Diff line number
Diff line change
@@ -1,10 +1,13 @@
1
1
---
2
2
title: render()
3
+
translators:
4
+
- liu-jin-yi
5
+
- QC-L
3
6
---
4
7
5
8
<Intro>
6
9
7
-
`render`renders a piece of [JSX](/learn/writing-markup-with-jsx) ("React element") into a browser DOM container node. It instructs React to change the DOM inside of the `container`so that it matches the passed JSX.
<p>This paragraph is not rendered by React (open index.html to verify).</p>
75
+
<p>这一段没有被 React 渲染(可以查看 index.html 进行验证)。</p>
73
76
<sectionid="comments"></section>
74
77
</main>
75
78
```
@@ -112,8 +115,8 @@ export function Comments() {
112
115
return (
113
116
<>
114
117
<h2>Comments</h2>
115
-
<Comment text="Hello!" author="Sophie"/>
116
-
<Comment text="How are you?" author="Sunil"/>
118
+
<Comment text="你好!" author="Sophie"/>
119
+
<Comment text="你是谁?" author="Sunil"/>
117
120
</>
118
121
);
119
122
}
@@ -134,9 +137,9 @@ nav ul li { display: inline-block; margin-right: 20px; }
134
137
135
138
<br />
136
139
137
-
## Updating the rendered tree {/*updating-the-rendered-tree*/}
140
+
## 更新已渲染的 DOM {/*updating-the-rendered-tree*/}
138
141
139
-
You can call`render` more than once on the same DOM node. As long as the component tree structure matches up with what was previously rendered, React will [preserve the state](/learn/preserving-and-resetting-state). Notice how you can type in the input:
142
+
你可以在同一 DOM 节点上多次调用`render`。只要组件树结构与之前渲染的内容一致,React 就会 [保留该状态](/learn/preserving-and-resetting-state) 。请仔细观察在输入框中输入内容后的效果:
140
143
141
144
<Sandpack>
142
145
@@ -159,30 +162,30 @@ export default function App({counter}) {
159
162
return (
160
163
<>
161
164
<h1>Hello, world! {counter}</h1>
162
-
<input placeholder="Type something here"/>
165
+
<input placeholder="在这里输入一些东西"/>
163
166
</>
164
167
);
165
168
}
166
169
```
167
170
168
171
</Sandpack>
169
172
170
-
You can destroy the rendered tree with [`unmountComponentAtNode()`](TODO).
173
+
你可以使用 [`unmountComponentAtNode()`](TODO) 来销毁已渲染的 DOM 树。
171
174
172
175
<br />
173
176
174
-
## When not to use it {/*when-not-to-use-it*/}
177
+
## 何时不使用它 {/*when-not-to-use-it*/}
175
178
176
-
*If your app uses server rendering and generates HTML on the server, use [`hydrate`](TODO)instead of `render`.
177
-
*If your app is fully built with React, you shouldn't need to use `render`more than once. If you want to render something in a different part of the DOM tree (for example, a modal or a tooltip), use [`createPortal`](TODO)instead.
*如果你的应用程序完全基于 React 构建,你大概率不需要多次使用 `render`函数。如果你想在 DOM 树的其他位置渲染内容(例如,modal 或者 tooltip),那么请使用 [`createPortal`](TODO)来代替。
178
181
179
182
<br />
180
183
181
184
182
-
## Behavior in detail {/*behavior-in-detail*/}
185
+
## 行为细节 {/*behavior-in-detail*/}
183
186
184
-
The first time you call `render`, any existing DOM elements inside `container`are replaced. If you call `render`again, React will update the DOM as necessary to reflect the latest JSX. React will decide which parts of the DOM can be reused and which need to be recreated by ["matching it up"](/learn/preserving-and-resetting-state)with the previously rendered tree. Calling `render`repeatedly is similar to calling `setState`--in both cases, React avoids unnecessary DOM updates.
187
+
在你第一次调用 `render` 时,`container`内的任何已有 DOM 元素都会被替换。如果你再次调用 `render`时,React 将会通过与先前渲染的组件树 ["匹配"](/learn/preserving-and-resetting-state)的方式,来决定 DOM 的哪些部分可以重用,哪些需要重新创建。重复调用 `render`与调用 `setState` 效果类似。无论哪种情况,React 都会避免不必要的 DOM 更新。
185
188
186
-
You can pass a callback as the third argument. React will call it after your component is in the DOM.
189
+
你可以将一个回调函数,作为 `render` 的第三个参数。React 会在你的组件在 DOM 中出现后,调用它。
187
190
188
-
If you render `<MyComponent />`, and`MyComponent`is a class component, `render`will return the instance of that class. In all other cases, it will return `null`.
0 commit comments