react-render-to-string
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

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 />);

Readme

Keywords

none

Package Sidebar

Install

npm i react-render-to-string

Weekly Downloads

119

Version

2.1.0

License

MIT

Unpacked Size

4.51 kB

Total Files

6

Last publish

Collaborators

  • fgnass