renderToStaticMarkupLink for this heading
January 6, 2025 · View on GitHub
renderToStaticMarkup renders a non-interactive React tree to an HTML string.
const html = renderToStaticMarkup(reactNode, options?)
ReferenceLink for Reference
renderToStaticMarkup(reactNode, options?)Link for this heading
On the server, call renderToStaticMarkup to render your app to HTML.
import { renderToStaticMarkup } from 'react-dom/server';
const html = renderToStaticMarkup(<Page />);
It will produce non-interactive HTML output of your React components.
ParametersLink for Parameters
reactNode: A React node you want to render to HTML. For example, a JSX node like<Page />.- optional
options: An object for server render.- optional
identifierPrefix: A string prefix React uses for IDs generated byuseId. Useful to avoid conflicts when using multiple roots on the same page.
- optional
ReturnsLink for Returns
An HTML string.
CaveatsLink for Caveats
renderToStaticMarkupoutput cannot be hydrated.renderToStaticMarkuphas limited Suspense support. If a component suspends,renderToStaticMarkupimmediately sends its fallback as HTML.renderToStaticMarkupworks in the browser, but using it in the client code is not recommended. If you need to render a component to HTML in the browser, get the HTML by rendering it into a DOM node.
UsageLink for Usage
Rendering a non-interactive React tree as HTML to a stringLink for Rendering a non-interactive React tree as HTML to a string
Call renderToStaticMarkup to render your app to an HTML string which you can send with your server response:
import { renderToStaticMarkup } from 'react-dom/server';
// The route handler syntax depends on your backend framework
app.use('/', (request, response) => {
const html = renderToStaticMarkup(<Page />);
response.send(html);
});
This will produce the initial non-interactive HTML output of your React components.
Pitfall
This method renders non-interactive HTML that cannot be hydrated. This is useful if you want to use React as a simple static page generator, or if you’re rendering completely static content like emails.
Interactive apps should use renderToString on the server and hydrateRoot on the client.
PreviousrenderToReadableStream
Copyright © Meta Platforms, Inc
no uwu plz
uwu?
Logo by@sawaratsuki1004
More
On this page
- Overview
- Reference
renderToStaticMarkup(reactNode, options?)- Usage
- Rendering a non-interactive React tree as HTML to a string
Search⌘CtrlK
-
react@19
- Overview
- Hooks
- Components
- APIs
-
react-dom@19
- Hooks
- Components
- APIs
- Client APIs
- Server APIs
- Static APIs
-
Rules of React
- Overview
-
React Server Components
- Server Components
- Server Functions
- Directives
-
Legacy APIs
- Legacy React APIs
Is this page useful?