react-render-to-string
v2.1.0
Published
Like renderToStaticMarkup but with suspense support.
Downloads
616
Readme
react-render-to-string
Like renderToStaticMarkup
but with suspense support.
The module is intended to be used with static site generators that support data fetching inside components rather than upfront.
It internally uses renderToReadableStream and captures the result as string.
Node.js vs. other runtimes
The package exports two different implementations, one for modern environments that support Web Streams, and one that uses renderToPipeableStream instead.
Note: Node.js supports Web Streams since v.16.5.0, but the exports map of react-dom/server
specifies a special build for "node"
that does not include renderToReadableStream
. Therefore, this package does the same and falls back to renderToPipeableStream
.
Usage
import renderToString from "react-render-to-string";
import { App } from "./App";
const html = await renderToString(<App />);