Question Bank

React ReactDOMServer: Two Explanations Quiz

Difficulty: Medium

Two explanations of `react-dom/server` rendering APIs (string vs streaming) plus companions on streaming SSR with `renderToPipeableStream` and on hydration mismatches.

Question Bank
/

React ReactDOMServer: Two Explanations Quiz

React ReactDOMServer: Two Explanations Quiz

Two explanations of `react-dom/server` rendering APIs (string vs streaming) plus companions on streaming SSR with `renderToPipeableStream` and on hydration mismatches.

Question Bank
Medium
JavaScript
4 questions
quiz
react
performance-optimization
interview-prep

482 views

15

Explain what react-dom/server's renderToString and renderToStaticMarkup do, and when you would reach for each. Include the trade-off around React's internal DOM attributes such as data-reactroot.

Examples

Example 1:

Input:
import { renderToString, renderToStaticMarkup } from 'react-dom/server';
renderToString(<App />);
renderToStaticMarkup(<App />);
Output:
renderToString -> HTML with React internal markers (used when the client will hydrate).
renderToStaticMarkup -> identical HTML without React internal markers (used for static pages).
Explanation: only renderToString produces output that React can later hydrate; renderToStaticMarkup is for pages that will never be rehydrated.