Skip to content

Commit 4226fbf

Browse files
authored
Edits to useId doc (#6464)
1 parent b1c4b4e commit 4226fbf

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

src/content/reference/react/useId.md

+17-24
Original file line numberDiff line numberDiff line change
@@ -303,39 +303,32 @@ input { margin: 5px; }
303303
304304
</Sandpack>
305305
306-
### useId in server rendering {/*useid-in-server-rendering*/}
306+
---
307307
308-
Choose a unique id prefix and pass it into the server options and client options. `useId` will return the same id string on server side and client side. The following example selects `react-app1` as the id prefix.
308+
### Using the same ID prefix on the client and the server {/*using-the-same-id-prefix-on-the-client-and-the-server*/}
309309
310-
```js
311-
import { useId } from 'react';
312-
313-
function App() {
314-
const id = useId();
315-
// ...
316-
317-
```
310+
If you [render multiple independent React apps on the same page](#specifying-a-shared-prefix-for-all-generated-ids), and some of these apps are server-rendered, make sure that the `identifierPrefix` you pass to the [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) call on the client side is the same as the `identifierPrefix` you pass to the [server APIs](https://react.dev/reference/react-dom/server) such as [`renderToPipeableStream`.](/reference/react-dom/server/renderToPipeableStream)
318311
319312
```js
320-
/**
321-
* server side
322-
*/
323-
324-
import ReactServer from 'react-dom/server';
325-
326-
const { pipe } = ReactServer.renderToPipeableStream(<App />, { identifierPrefix: 'react-app1' });
327-
// ...
313+
// Server
314+
import { renderToPipeableStream } from 'react-dom/server';
328315

316+
const { pipe } = renderToPipeableStream(
317+
<App />,
318+
{ identifierPrefix: 'react-app1' }
319+
);
329320
```
330321
331322
```js
332-
/**
333-
* client side
334-
*/
335-
323+
// Client
336324
import { hydrateRoot } from 'react-dom/client';
337325

338326
const domNode = document.getElementById('root');
339-
const root = hydrateRoot(domNode, reactNode, { identifierPrefix: 'react-app1' });
340-
327+
const root = hydrateRoot(
328+
domNode,
329+
reactNode,
330+
{ identifierPrefix: 'react-app1' }
331+
);
341332
```
333+
334+
You do not need to pass `identifierPrefix` if you only have one React app on the page.

0 commit comments

Comments
 (0)