Hydrate an SSR app
Server-side rendered application
React 19+ · Function
hydrateRoot attaches React to HTML previously rendered on the server, making it interactive in the browser. The client React tree must produce output identical to the server-rendered HTML.
Call hydrateRoot in the browser with the same React tree used to generate the server HTML. React attaches to the existing markup and takes over DOM management; the client output must match the server output, after which the returned root can render updates or unmount the tree.
hydrateRoot(domNode, reactNode, options?)| Name | Type | Description |
|---|---|---|
domNode | Element | Document | A DOM element rendered as the root element on the server; pass document to hydrate the entire document. |
reactNode | ReactNode | The React node used to render the existing HTML, commonly JSX such as <App />. |
options | object | Optional configuration for hydration and error handling. |
An object with render and unmount methods.
import { hydrateRoot } from 'react-dom/client';
import App from './App';
const domNode = document.getElementById('root');
if (domNode) {
hydrateRoot(domNode, <App />);
}Hydrates server-rendered markup in the root element and makes the rendered application interactive.
Server-side rendered application
Streaming server rendering
Whole-document rendering
Progressive server-rendered UI
createRootrenderToPipeableStreamrenderToReadableStreamrenderToString