renderToStaticMarkup


Reference

renderToStaticMarkup(reactNode, options?)

On the server, call renderToStaticMarkup to render your app to HTML.

It will produce non-interactive HTML output of your React components.

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 by Useful to avoid conflicts when using multiple roots on the same page.

Returns

An HTML string.

Caveats

  • renderToStaticMarkup output cannot be hydrated.

  • renderToStaticMarkup has limited Suspense support. If a component suspends, renderToStaticMarkup immediately sends its fallback as HTML.

  • renderToStaticMarkup works 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,


Usage

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:

This will produce the initial non-interactive HTML output of your React components.