# prerender()

> The `prerender()` API in React DOM renders a React tree to static HTML using Web Streams, waiting for all data to load.

## How do I generate static HTML from React with prerender?

The API from 'react-dom/static' that renders a tree to a stream of static HTML, waiting for all data and Suspense boundaries to load before resolving. The result's `prelude` is written to a file or response. Designed for static site generation.

- Topic: Server APIs [React DOM]
- Type: API

## Example

Wrong:

```jsx
const html = renderToString(<App />);
await writeFile('dist/index.html', html);
```

Right:

```jsx
const { prelude } = await prerender(<App />, {
  bootstrapScripts: ['/main.js'],
});
const html = await new Response(prelude).text();
await writeFile('dist/index.html', html);
```

`prerender` waits for all `<Suspense>` data to load, so the static file contains real content instead of fallbacks.

## Common mistakes

- Using `renderToString` for static pages and getting Suspense fallbacks instead of data.

## Key points

- `prerender` is imported from 'react-dom/static' and used for static generation, not per-request streaming.
- The returned `prelude` stream is what gets written to the HTML file or response.
- An `AbortSignal` with a timeout is passed so slow data cannot hang the build.

## Interview questions

### prerender vs renderToReadableStream: what is the difference?

`renderToReadableStream` streams while data loads, for live requests. `prerender` waits for all data and returns finished HTML for static files.

### How do I use prerender in Node?

Use `prerenderToNodeStream` from 'react-dom/static', which works the same way but returns a Node stream.

## Related cards

- [SSG](https://wonderium.dev/web/ssg.md)
- [renderToReadableStream()](https://wonderium.dev/react/render-to-readable-stream.md)
- [`<Suspense>`](https://wonderium.dev/react/suspense.md)
- [renderToString()](https://wonderium.dev/react/render-to-string.md)
- [Streaming SSR](https://wonderium.dev/web/streaming-ssr.md)

---

- Level: [React](https://wonderium.dev/react.md)
- HTML version: https://wonderium.dev/react/prerender
- Last updated: 2026-11-25
