Generate initial HTML for an application response
Server-side rendering
React 19+ · Function
Renders a React tree to an HTML string, typically on the server for the initial page response. Hydrate the resulting markup with hydrateRoot in the browser to make it interactive.
Call renderToString with a React node on the server to produce its initial HTML markup as a string. Send that markup in the server response, then use hydrateRoot in the browser to attach React behavior and make the generated HTML interactive.
renderToString(reactNode, options?)| Name | Type | Description |
|---|---|---|
reactNode | ReactNode | A React node to render as HTML, such as a JSX element like <App />. |
options | object | undefined | Optional server-rendering configuration object. |
options.identifierPrefix | string | undefined | Optional string prefix for IDs generated by useId; use the same value with hydrateRoot. |
An HTML string.
import { renderToString } from 'react-dom/server';
import { hydrateRoot } from 'react-dom/client';
import App from './App';
const html = renderToString(<App />);
// Server: include `html` in the response body.
// Client entry point:
hydrateRoot(document, <App />);Renders the initial server HTML, then hydrates the same application in the browser to make it interactive.
Server-side rendering
Progressive enhancement
Multiple roots
hydrateRootrenderToPipeableStreamrenderToReadableStreamprerenderresume