Skip to content

Commit 573fdc7

Browse files
Merge pull request #305 from reactjs/fix/conflict
fix: resolved conflict
2 parents f5fc6a2 + aa3d02c commit 573fdc7

File tree

3 files changed

+40
-130
lines changed

3 files changed

+40
-130
lines changed

content/docs/reference-react-dom.md

+35-90
Original file line numberDiff line numberDiff line change
@@ -6,135 +6,99 @@ category: Reference
66
permalink: docs/react-dom.html
77
---
88

9-
<<<<<<< HEAD
10-
如果使用 `<script>` 標籤載入 React 這些頂層 API 就可以在全域 `ReactDOM` 上找到。如果你使用 ES6 和 npm,你可以寫成 `import ReactDOM from 'react-dom'`。如果你使用 ES5 和 npm,你可以寫成 `var ReactDOM = require('react-dom')`
11-
=======
12-
The `react-dom` package provides DOM-specific methods that can be used at the top level of your app and as an escape hatch to get outside the React model if you need to.
9+
`react-dom` 提供了 DOM 的特定方法讓你可以在你的應用程式頂層使用,如果有需要,也可以作為一個逃生窗口來脫離 React 模型。
1310

1411
```js
1512
import * as ReactDOM from 'react-dom';
1613
```
1714

18-
If you use ES5 with npm, you can write:
15+
如果你使用 ES5 npm,你可以這樣寫:
1916

2017
```js
2118
var ReactDOM = require('react-dom');
2219
```
2320

24-
The `react-dom` package also provides modules specific to client and server apps:
21+
`react-dom` package 也提供了特定於 client server 應用程式的 module:
2522
- [`react-dom/client`](/docs/react-dom-client.html)
2623
- [`react-dom/server`](/docs/react-dom-server.html)
27-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1
2824

2925
## 概覽 {#overview}
3026

31-
<<<<<<< HEAD
32-
`react-dom` package 提供了特定於 DOM 的方法,可以被用在你的應用程式的頂層,也可以作為 React model 的出口。大部分你的 component 不應該需要使用到這個模組。
33-
=======
34-
The `react-dom` package exports these methods:
27+
`react-dom` package export 這些方法:
3528
- [`createPortal()`](#createportal)
3629
- [`flushSync()`](#flushsync)
37-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1
3830

39-
These `react-dom` methods are also exported, but are considered legacy:
31+
這些 `react-dom` 方法也被 export,但是被視為是 legacy
4032
- [`render()`](#render)
4133
- [`hydrate()`](#hydrate)
4234
- [`findDOMNode()`](#finddomnode)
4335
- [`unmountComponentAtNode()`](#unmountcomponentatnode)
4436

45-
> Note:
46-
>
47-
> Both `render` and `hydrate` have been replaced with new [client methods](/docs/react-dom-client.html) in React 18. These methods will warn that your app will behave as if it's running React 17 (learn more [here](https://reactjs.org/link/switch-to-createroot)).
37+
> 注意:
38+
>
39+
> `render` `hydrate` 兩者在 React 18 已經替換為新的 [client 方法](/docs/react-dom-client.html)。如果你使用像是 React 17 方式,這些方法將警告你的應用程式的行為。([從這裡](https://reactjs.org/link/switch-to-createroot)了解更多)。
4840
4941
### 瀏覽器支援 {#browser-support}
5042

51-
<<<<<<< HEAD
52-
React 支援所有主流瀏覽器包含 IE 9 和以上,儘管舊版瀏覽器像是 IE 9 和 IE 10 [需要一些 polyfill](/docs/javascript-environment-requirements.html)
53-
=======
54-
React supports all modern browsers, although [some polyfills are required](/docs/javascript-environment-requirements.html) for older versions.
55-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1
43+
React 支援所有主流瀏覽器,雖然對於一些舊版瀏覽器[需要一些 polyfill](/docs/javascript-environment-requirements.html)
5644

5745
> 注意:
5846
>
59-
<<<<<<< HEAD
60-
> 我們不支援那些較舊的不支援 ES5 方法的瀏覽器,但如果頁面上包含了像是 [es5-shim 和 es5-sham](https://github.com/es-shims/es5-shim) 等 polyfill 你可能會發現你的應用程式在較舊的瀏覽器上仍可使用。如果你選擇了這條不歸路你就只能靠你自己了。
61-
62-
* * *
63-
=======
64-
> We do not support older browsers that don't support ES5 methods or microtasks such as Internet Explorer. You may find that your apps do work in older browsers if polyfills such as [es5-shim and es5-sham](https://github.com/es-shims/es5-shim) are included in the page, but you're on your own if you choose to take this path.
65-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1
47+
> 我們不支援那些較舊不支援 ES5 方法或是 microtasks 的瀏覽器,像是 Internet Explorer。但如果頁面上引入了像是 [es5-shim 和 es5-sham](https://github.com/es-shims/es5-shim) 等 polyfill 你可能會發現你的應用程式在較舊的瀏覽器上仍可使用,但如果你選擇了這條路你就只能靠你自己了。
6648
67-
## Reference {#reference}
49+
## 參考 {#reference}
6850

6951
### `createPortal()` {#createportal}
7052

7153
```javascript
7254
createPortal(child, container)
7355
```
7456

75-
<<<<<<< HEAD
76-
`container` 內 render 一個 React element 並回傳一個 [reference](/docs/more-about-refs.html) 到 component(或者是 [stateless components](/docs/components-and-props.html#function-and-class-components) 則回傳 `null`)。
77-
=======
78-
Creates a portal. Portals provide a way to [render children into a DOM node that exists outside the hierarchy of the DOM component](/docs/portals.html).
57+
提供了一個方式將 children [render 存在於 DOM component 層次結構之外的 DOM 節點中](/docs/portals.html)
7958

8059
### `flushSync()` {#flushsync}
8160

8261
```javascript
8362
flushSync(callback)
8463
```
8564

86-
Force React to flush any updates inside the provided callback synchronously. This method is useful for being able to read the result of those updates immediately.
87-
88-
> Note:
89-
>
90-
> `flushSync` can have a significant impact on performance. Use sparingly.
91-
>
92-
> `flushSync` may force pending Suspense boundaries to show their `fallback` state.
93-
>
94-
> `flushSync` may also run pending effects and synchronously apply any updates they contain before returning.
95-
>
96-
> `flushSync` may also flush updates outside the callback when necessary to flush the updates inside the callback. For example, if there are pending updates from a click, React may flush those before flushing the updates inside the callback.
65+
> 注意:
66+
>
67+
> `flushSync` 可能會對效能產生重大的影響。謹慎使用。
68+
>
69+
> `flushSync` 可能會迫使 pending 的 Suspense boundary 顯示 `fallback` 狀態。
70+
>
71+
> `flushSync` 也可以執行 pending effects,並在回傳之前同步 apply 它們包含的任何更新。
72+
>
73+
> `flushSync` `flushSync` 在必要時也可以在 callback 外 flush 更新,以 flush callback 内的更新。例如,如果有來自 click 的 pending 更新,React 可能會在 flush callback 中的更新之前 flush 這些内容。
9774
98-
## Legacy Reference {#legacy-reference}
75+
## Legacy 參考 {#legacy-reference}
9976
### `render()` {#render}
10077
```javascript
10178
render(element, container[, callback])
10279
```
10380

104-
> Note:
81+
> 注意:
10582
>
106-
> `render` has been replaced with `createRoot` in React 18. See [createRoot](/docs/react-dom-client.html#createroot) for more info.
83+
> `render` 在 React 18 已經被 `createRoot` 取代。更多資訊請參考 [createRoot](/docs/react-dom-client.html#createroot)
10784
108-
Render a React element into the DOM in the supplied `container` and return a [reference](/docs/more-about-refs.html) to the component (or returns `null` for [stateless components](/docs/components-and-props.html#function-and-class-components)).
109-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1
85+
將一個 React elemnt render 到提供提供的 `container` 的 DOM 中,並回傳一個該 component 的 [reference](/docs/more-about-refs.html)(對於 [stateless components](/docs/components-and-props.html#function-and-class-components) 回傳 `null`)。
11086

11187
如果 React element 之前已經在 `container` 內被 render,它只會執行更新並 mutate 必要的 DOM,來呈現最新的 React element。
11288

11389
如果提供了可選的 callback,它將會在 component 被 render 或更新之後,才被執行。
11490

11591
> 注意:
11692
>
117-
<<<<<<< HEAD
118-
> `ReactDOM.render()` 控制了你傳入到 container 內的 node 內容。當第一次被呼叫時,任何存在於 container 的 DOM element 都會被替換。之後的呼叫會使用 React 的 DOM diffing 演算法進行高效率的更新。
93+
> `render()` 控制了你傳入到 container 內的 node 內容。當第一次被呼叫時,任何存在於 container 的 DOM element 都會被替換。之後的呼叫會使用 React 的 DOM diffing 演算法進行高效率的更新。
11994
>
120-
> `ReactDOM.render()` 不修改 container 的 node(只修改 container 的 children)。它可以將 component 插入一個現有的 DOM node 而不用覆蓋已經存在的 children。
95+
> `render()` 不修改 container 的 node(只修改 container 的 children)。它可以將 component 插入一個現有的 DOM node 而不用覆蓋已經存在的 children。
12196
>
122-
> `ReactDOM.render()` 目前回傳一個 reference 到 root `ReactComponent` instance。然而,使用這個回傳值是被遺留的方式
97+
> `render()` 目前回傳一個 reference 到 root `ReactComponent` instance。然而,使用這個回傳值是被遺留的方式
12398
> 並且應該被避免,因為未來版本的 React 在某些情況下可能會非同步地 render component。如果你需要 reference 到 root `ReactComponent` instance,首選的解決方式是附加一個
12499
> [callback ref](/docs/refs-and-the-dom.html#callback-refs) 在 root element 上。
125100
>
126-
> 使用 `ReactDOM.render()` 來 hydrate 一個 server-render container 已經被棄用,並且在 React 17 將會被移除。使用 [`hydrate()`](#hydrate) 作為代替。
127-
=======
128-
> `render()` controls the contents of the container node you pass in. Any existing DOM elements inside are replaced when first called. Later calls use React’s DOM diffing algorithm for efficient updates.
129-
>
130-
> `render()` does not modify the container node (only modifies the children of the container). It may be possible to insert a component to an existing DOM node without overwriting the existing children.
131-
>
132-
> `render()` currently returns a reference to the root `ReactComponent` instance. However, using this return value is legacy
133-
> and should be avoided because future versions of React may render components asynchronously in some cases. If you need a reference to the root `ReactComponent` instance, the preferred solution is to attach a
134-
> [callback ref](/docs/refs-and-the-dom.html#callback-refs) to the root element.
135-
>
136-
> Using `render()` to hydrate a server-rendered container is deprecated. Use [`hydrateRoot()`](#hydrateroot) instead.
137-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1
101+
> 使用 `render()` 來 hydrate 一個 server-render container 已經被棄用。使用 [`hydrateRoot()`](#hydrateroot) 作為代替。
138102
139103
* * *
140104

@@ -144,15 +108,11 @@ Render a React element into the DOM in the supplied `container` and return a [re
144108
hydrate(element, container[, callback])
145109
```
146110

147-
<<<<<<< HEAD
148-
[`render()`](#render) 相同,但用來 hydrate 其 HTML 內容由 [`ReactDOMServer`](/docs/react-dom-server.html) 所 render 的 container 。React 將會嘗試附加 event listener 到現有的 markup。
149-
=======
150-
> Note:
111+
> 注意:
151112
>
152-
> `hydrate` has been replaced with `hydrateRoot` in React 18. See [hydrateRoot](/docs/react-dom-client.html#hydrateroot) for more info.
113+
> `hydrate` 在 React 18 已經被 `hydrateRoot` 取代。更多資訊請參考 [hydrateRoot](/docs/react-dom-client.html#hydrateroot)
153114
154-
Same as [`render()`](#render), but is used to hydrate a container whose HTML contents were rendered by [`ReactDOMServer`](/docs/react-dom-server.html). React will attempt to attach event listeners to the existing markup.
155-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1
115+
如同 [`render()`](#render),但它是被用來 hydrate 一個 container,其 HTML 內容是由 [`ReactDOMServer`](/docs/react-dom-server.html) render。React 將嘗試將 event listener attach 到現有 markup 上。s
156116

157117
React 預期在伺服器端和客戶端所 render 的內容是相同的。它可以修補 text content 的差異,但你應該把不匹配的部分視為 bug 並且修正。在開發模式中,React 會警告關於 hydration 過程中的不匹配。在不匹配的情況下,將無法保證 attribute 的差異會被修補。這對於效能來說很重要,因為在大部分的應用程式中,不匹配的情況很少見,也因此驗證要所有 markup 的成本非常高。
158118

@@ -170,15 +130,11 @@ React 預期在伺服器端和客戶端所 render 的內容是相同的。它可
170130
unmountComponentAtNode(container)
171131
```
172132

173-
<<<<<<< HEAD
174-
從 DOM 之中移除一個已經 mount 的 React component 並清除其 event handler 和 state。如果 container 中沒有 mount 任何 component,呼叫此 function 不會執行任何操作。如果一個 component 被 unmount 則回傳 `true`,而如果沒有要 unmount 的 component 則回傳 `false`
175-
=======
176-
> Note:
133+
> 注意:
177134
>
178-
> `unmountComponentAtNode` has been replaced with `root.unmount()` in React 18. See [createRoot](/docs/react-dom-client.html#createroot) for more info.
135+
> `unmountComponentAtNode` 在 React 18 已經被 `root.unmount()` 取代。更多資訊請參考 [createRoot](/docs/react-dom-client.html#createroot)
179136
180-
Remove a mounted React component from the DOM and clean up its event handlers and state. If no component was mounted in the container, calling this function does nothing. Returns `true` if a component was unmounted and `false` if there was no component to unmount.
181-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1
137+
從 DOM 移除一個 mount React component 並清除它的 event handler 以及 state。如果沒有 component 被 mount 在 container 的話,呼叫這個 function 並不會做任何事。如果一個 component 被 unmount 回傳一個 `true`,反之如果沒有 component 被 unmount,回傳 `false`
182138

183139
* * *
184140

@@ -202,14 +158,3 @@ findDOMNode(component)
202158
> `findDOMNode` 不能被用在 function component。
203159
204160
* * *
205-
<<<<<<< HEAD
206-
207-
### `createPortal()` {#createportal}
208-
209-
```javascript
210-
ReactDOM.createPortal(child, container)
211-
```
212-
213-
創建 portal。Portal 提供了一種方法來 [render children 為存在於 DOM component 層級結構之外的 DOM node](/docs/portals.html)
214-
=======
215-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1

content/docs/reference-react.md

+2-20
Original file line numberDiff line numberDiff line change
@@ -339,21 +339,11 @@ const SomeComponent = React.lazy(() => import('./SomeComponent'));
339339

340340
請注意當你使用 `lazy` component 的時候,你的 render tree 上層中必須包含一個 `<React.Suspense>` 來指定 loading indicator。
341341

342-
<<<<<<< HEAD
343-
> 備註
344-
>
345-
> 當你同時使用 `React.lazy` 以及動態 import 的時候,你的 JS 環境必須支援 Promise。IE11 以下的瀏覽器將需要 polyfill。
346-
347-
### `React.Suspense` {#reactsuspense}
348-
349-
`React.Suspense` 讓你指定當底下的 component 還沒準備好 render 的時候所用的 loading indicator。目前 `<React.Suspense>` **只支援** 動態載入的 component。
350-
=======
351342
### `React.Suspense` {#reactsuspense}
352343

353344
`React.Suspense` lets you specify the loading indicator in case some components in the tree below it are not yet ready to render. In the future we plan to let `Suspense` handle more scenarios such as data fetching. You can read about this in [our roadmap](/blog/2018/11/27/react-16-roadmap.html).
354345

355346
Today, lazy loading components is the **only** use case supported by `<React.Suspense>`:
356-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1
357347

358348
```js
359349
// This component is loaded dynamically
@@ -373,23 +363,16 @@ function MyComponent() {
373363

374364
在我們的 [code splitting 文件](/docs/code-splitting.html#reactlazy) 有更多資訊。請注意 `lazy` component 可以在 `Suspense` tree 中底下很多層 ── 你不需要把每一個 `lazy` 元素包起來。最好的方法是將 `<Suspense>` 放在你想看到 loading indicator 的地方,而在所有你想進行 code splitting 的地方使用 `lazy()`
375365

376-
<<<<<<< HEAD
377-
雖然目前還不支援其他情境,我們在未來會讓 `Suspense` 處理更多像是抓取資料的情境。你可以在[我們的未來計畫](/blog/2018/11/27/react-16-roadmap.html)中讀到更多資訊。
378-
379-
> 備註
366+
> 注意
380367
>
381-
> `ReactDOMServer` 還沒支援 `React.lazy()``<React.Suspense>`。這是一個目前已知的限制,並會在未來解決。
382-
=======
383-
> Note
384-
>
385368
> For content that is already shown to the user, switching back to a loading indicator can be disorienting. It is sometimes better to show the "old" UI while the new UI is being prepared. To do this, you can use the new transition APIs [`startTransition`](#starttransition) and [`useTransition`](/docs/hooks-reference.html#usetransition) to mark updates as transitions and avoid unexpected fallbacks.
386369

387370
#### `React.Suspense` in Server Side Rendering {#reactsuspense-in-server-side-rendering}
388371
During server side rendering Suspense Boundaries allow you to flush your application in smaller chunks by suspending.
389372
When a component suspends we schedule a low priority task to render the closest Suspense boundary's fallback. If the component unsuspends before we flush the fallback then we send down the actual content and throw away the fallback.
390373
391374
#### `React.Suspense` during hydration {#reactsuspense-during-hydration}
392-
Suspense boundaries depend on their parent boundaries being hydrated before they can hydrate, but they can hydrate independently from sibling boundaries. Events on a boundary before its hydrated will cause the boundary to hydrate at
375+
Suspense boundaries depend on their parent boundaries being hydrated before they can hydrate, but they can hydrate independently from sibling boundaries. Events on a boundary before its hydrated will cause the boundary to hydrate at
393376
a higher priority than neighboring boundaries. [Read more](https://github.com/reactwg/react-18/discussions/130)
394377
395378
### `React.startTransition` {#starttransition}
@@ -406,4 +389,3 @@ React.startTransition(callback)
406389
> Updates in a transitions will not show a fallback for re-suspended content, allowing the user to continue interacting while rendering the update.
407390
>
408391
> `React.startTransition` does not provide an `isPending` flag. To track the pending status of a transition see [`React.useTransition`](/docs/hooks-reference.html#usetransition).
409-
>>>>>>> 707f22d25f5b343a2e5e063877f1fc97cb1f48a1

0 commit comments

Comments
 (0)