Compare SSR and static rendering
Choose when HTML is produced
Client-side rendering (CSR) builds the interface in the browser from JavaScript. Server-side rendering (SSR) produces HTML on the server for a request; static site generation (SSG) produces HTML ahead of requests, for example at build time. Hydration makes compatible pre-rendered markup interactive by attaching React in the browser. These strategies can coexist on different routes. A static HTML document may need no client JavaScript; a pre-rendered interactive React app does. SSR does not automatically imply React Server Components (RSC): server rendering produces HTML, whereas RSC uses a separate component transport and bundler integration. A framework usually coordinates assets, routing and rendering. These local examples target matching, approved patched React/React DOM versions; React 18 supports the basic string/stream APIs, React 19 adds static prerender APIs.
import React from 'react';import {renderToString} from 'react-dom/server';export function catalogueMarkup() { return renderToString(<section><h2>Seed catalogue</h2><p>Three seed packets available.</p></section>);}Call catalogueMarkup in a server-side module to obtain a string containing the heading and paragraph. The string is not the complete HTML document and cannot respond to clicks by itself. To hydrate it, the client must render the same tree into its matching container. renderToString does not stream or wait for a suspended resource: a Suspense fallback may appear in its output. Do not treat this as a full application server. A production framework can use streaming APIs for asynchronous data.
Generate static content without a client bundle
import React from 'react';import {renderToStaticMarkup} from 'react-dom/server';export function printableNotice() { return '<!doctype html>'+renderToStaticMarkup(<html lang="en"><head><title>Garden notice</title></head><body><main><h1>Planting day</h1><p>Bring a labelled seed packet.</p></main></body></html>);}Save the returned complete document to a lab-owned HTML file and open it locally. The title and instructions are visible without a React client bundle. renderToStaticMarkup output is not intended for hydration. Static generation is a timing choice, not this API alone: a statically generated application can use hydratable output and a browser bundle. Never place private, per-user records into publicly cached build output. Regenerate or invalidate static content when its data changes.
Prerender a page with a React 19 static API
import React from 'react';import {prerenderToNodeStream} from 'react-dom/static';export async function generateGardenPage() { const {prelude} = await prerenderToNodeStream(<html lang="en"><head><title>Seed guide</title></head><body><main><h1>Seed guide</h1><p>Store packets in a dry place.</p></main></body></html>); const chunks=[]; for await (const chunk of prelude) chunks.push(Buffer.from(chunk)); return Buffer.concat(chunks).toString('utf8');}Unlike the string renderer, the static prerender family can wait for Suspense data before returning its prelude. This fixture has no asynchronous data, so it demonstrates the API shape and complete-document output rather than measuring waiting. The function consumes a Node stream into a string for a tiny local page; large outputs should be streamed to a reviewed destination. In Web Streams environments use prerender. For an interactive static page, configure the matching client bundle and hydration. Choose SSR for request-specific freshness, SSG for reusable stable content and CSR for client-driven interfaces when an initial HTML shell is sufficient. These are trade-offs: none guarantees better speed, SEO or accessibility. Compare time to first content, interactivity, cache scope and server costs. Practice: choose a strategy for a printed guide, a private dashboard and an interactive public catalogue.