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: src/content/reference/react-dom/hydrate.md
+34-34
Original file line number
Diff line number
Diff line change
@@ -4,15 +4,15 @@ title: hydrate
4
4
5
5
<Deprecated>
6
6
7
-
This API will be removed in a future major version of React.
7
+
この API は、今後のメジャーバージョンの React で削除される予定です。
8
8
9
-
In React 18, `hydrate`was replaced by [`hydrateRoot`.](/reference/react-dom/client/hydrateRoot) Using `hydrate`in React 18 will warn that your app will behave as if it’s running React 17. Learn more [here.](/blog/2022/03/08/react-18-upgrade-guide#updates-to-client-rendering-apis)
`hydrate`lets you display React components inside a browser DOM node whose HTML content was previously generated by [`react-dom/server`](/reference/react-dom/server)in React 17 and below.
15
+
`hydrate`を使用すると、React 17 以前の [`react-dom/server`](/reference/react-dom/server)によって事前生成した HTML コンテンツが含まれるブラウザ DOM ノード内に、React コンポーネントを表示できます。
React will attach to the HTML that exists inside the `domNode`, and take over managing the DOM inside it. An app fully built with React will usually only have one `hydrate`call with its root component.
39
+
React は、`domNode` 内に存在する HTML にアタッチし、その内部の DOM の管理を引き継ぎます。React で完全に構築されたアプリには、ルートコンポーネントを引数にした `hydrate`呼び出しが通常 1 つのみ存在します。
40
40
41
-
[See more examples below.](#usage)
41
+
[さらに例を見る](#usage)
42
42
43
-
#### Parameters {/*parameters*/}
43
+
#### 引数 {/*parameters*/}
44
44
45
-
* `reactNode`: The "React node" used to render the existing HTML. This will usually be a piece of JSX like `<App />` which was rendered with a `ReactDOM Server`method such as`renderToString(<App />)` in React 17.
* `hydrate`expects the rendered content to be identical with the server-rendered content. React can patch up differences in text content, but you should treat mismatches as bugs and fix them.
57
-
* In development mode, React warns about mismatches during hydration. There are no guarantees that attribute differences will be patched up in case of mismatches. This is important for performance reasons because in most apps, mismatches are rare, and so validating all markup would be prohibitively expensive.
58
-
* You'll likely have only one `hydrate`call in your app. If you use a framework, it might do this call for you.
59
-
* If your app is client-rendered with no HTML rendered already, using `hydrate()`is not supported. Use [render()](/reference/react-dom/render) (for React 17 and below) or [createRoot()](/reference/react-dom/client/createRoot) (for React 18+) instead.
Using `hydrate()`to render a client-only app (an app without server-rendered HTML) is not supported. Use [`render()`](/reference/react-dom/render) (in React 17 and below) or [`createRoot()`](/reference/react-dom/client/createRoot) (in React 18+) instead.
73
+
`hydrate()`を使用して、クライアントのみのアプリ(サーバでレンダーされた HTML がないアプリ)をレンダーすることはサポートされていません。代わりに、React 17 以前では [`render()`](/reference/react-dom/render)、React 18 以降では [`createRoot()`](/reference/react-dom/client/createRoot) を使用してください。
74
74
75
-
### Hydrating server-rendered HTML {/*hydrating-server-rendered-html*/}
75
+
### サーバでレンダーされた HTML のハイドレーション {/*hydrating-server-rendered-html*/}
76
76
77
-
In React, "hydration" is how React "attaches" to existing HTML that was already rendered by React in a server environment. During hydration, React will attempt to attach event listeners to the existing markup and take over rendering the app on the client.
@@ -104,17 +104,17 @@ export default function App() {
104
104
105
105
</Sandpack>
106
106
107
-
Usually you shouldn't need to call `hydrate`again or to call it in more places. From this point on, React will be managing the DOM of your application. To update the UI, your components will [use state.](/reference/react/useState)
107
+
通常、`hydrate`を再度呼び出したり、複数の場所で呼び出したりする必要はありません。ここから先は、React がアプリケーションの DOM を管理しています。UI を更新するには、コンポーネントは [state を使うことになるでしょう。](/reference/react/useState)
108
108
109
-
For more information on hydration, see the docs for [`hydrateRoot`.](/reference/react-dom/client/hydrateRoot)
If a single element’s attribute or text content is unavoidably different between the server and the client (for example, a timestamp), you may silence the hydration mismatch warning.
@@ -146,13 +146,13 @@ export default function App() {
146
146
147
147
</Sandpack>
148
148
149
-
This only works one level deep, and is intended to be an escape hatch. Don’t overuse it. Unless it’s text content, React still won’t attempt to patch it up, so it may remain inconsistent until future updates.
If you intentionally need to render something different on the server and the client, you can do a two-pass rendering. Components that render something different on the client can read a [state variable](/reference/react/useState) like `isClient`, which you can set to `true` in an [effect](/reference/react/useEffect):
@@ -192,10 +192,10 @@ export default function App() {
192
192
193
193
</Sandpack>
194
194
195
-
This way the initial render pass will render the same content as the server, avoiding mismatches, but an additional pass will happen synchronously right after hydration.
This approach makes hydration slower because your components have to render twice. Be mindful of the user experience on slow connections. The JavaScript code may load significantly later than the initial HTML render, so rendering a different UI immediately after hydration may feel jarring to the user.
199
+
このアプローチではコンポーネントを 2 回レンダーする必要があるためハイドレーションが遅くなります。低速な接続におけるユーザ体験に注意してください。JavaScript コードは初期レンダーされた HTML よりもかなり遅く読み込まれる場合があるため、ハイドレーション直後に異なる UI をレンダーするとユーザに不快感を与えるかもしれません。
0 commit comments