{"componentChunkName":"component---src-templates-docs-js","path":"/docs/react-dom-server.html","result":{"data":{"markdownRemark":{"html":"<p>The <code class=\"gatsby-code-text\">ReactDOMServer</code> object enables you to render components to static markup. Typically, it’s used on a Node server:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token comment\">// ES modules</span>\n<span class=\"token keyword\">import</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">as</span> ReactDOMServer <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom/server'</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// CommonJS</span>\n<span class=\"token keyword\">var</span> ReactDOMServer <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'react-dom/server'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<h2 id=\"overview\"><a href=\"#overview\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Overview </h2>\n<p>These methods are only available in the <strong>environments with <a href=\"https://nodejs.dev/learn/nodejs-streams\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Node.js Streams</a>:</strong></p>\n<ul>\n<li><a href=\"#rendertopipeablestream\"><code class=\"gatsby-code-text\">renderToPipeableStream()</code></a></li>\n<li><a href=\"#rendertonodestream\"><code class=\"gatsby-code-text\">renderToNodeStream()</code></a> (Deprecated)</li>\n<li><a href=\"#rendertostaticnodestream\"><code class=\"gatsby-code-text\">renderToStaticNodeStream()</code></a></li>\n</ul>\n<p>These methods are only available in the <strong>environments with <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Streams_API\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Web Streams</a></strong> (this includes browsers, Deno, and some modern edge runtimes):</p>\n<ul>\n<li><a href=\"#rendertoreadablestream\"><code class=\"gatsby-code-text\">renderToReadableStream()</code></a></li>\n</ul>\n<p>The following methods can be used in the environments that don’t support streams:</p>\n<ul>\n<li><a href=\"#rendertostring\"><code class=\"gatsby-code-text\">renderToString()</code></a></li>\n<li><a href=\"#rendertostaticmarkup\"><code class=\"gatsby-code-text\">renderToStaticMarkup()</code></a></li>\n</ul>\n<h2 id=\"reference\"><a href=\"#reference\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Reference </h2>\n<h3 id=\"rendertopipeablestream\"><a href=\"#rendertopipeablestream\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code class=\"gatsby-code-text\">renderToPipeableStream()</code> </h3>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\">ReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToPipeableStream</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Render a React element to its initial HTML. Returns a stream with a <code class=\"gatsby-code-text\">pipe(res)</code> method to pipe the output and <code class=\"gatsby-code-text\">abort()</code> to abort the request. Fully supports Suspense and streaming of HTML with “delayed” content blocks “popping in” via inline <code class=\"gatsby-code-text\">&lt;script></code> tags later. <a href=\"https://github.com/reactwg/react-18/discussions/37\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Read more</a></p>\n<p>If you call <a href=\"/docs/react-dom-client.html#hydrateroot\"><code class=\"gatsby-code-text\">ReactDOM.hydrateRoot()</code></a> on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token keyword\">let</span> didError <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> stream <span class=\"token operator\">=</span> <span class=\"token function\">renderToPipeableStream</span><span class=\"token punctuation\">(</span>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">App</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">onShellReady</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token comment\">// The content above all Suspense boundaries is ready.</span>\n      <span class=\"token comment\">// If something errored before we started streaming, we set the error code appropriately.</span>\n      res<span class=\"token punctuation\">.</span>statusCode <span class=\"token operator\">=</span> didError <span class=\"token operator\">?</span> <span class=\"token number\">500</span> <span class=\"token operator\">:</span> <span class=\"token number\">200</span><span class=\"token punctuation\">;</span>\n      res<span class=\"token punctuation\">.</span><span class=\"token function\">setHeader</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Content-type'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'text/html'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      stream<span class=\"token punctuation\">.</span><span class=\"token function\">pipe</span><span class=\"token punctuation\">(</span>res<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">onShellError</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token comment\">// Something errored before we could complete the shell so we emit an alternative shell.</span>\n      res<span class=\"token punctuation\">.</span>statusCode <span class=\"token operator\">=</span> <span class=\"token number\">500</span><span class=\"token punctuation\">;</span>\n      res<span class=\"token punctuation\">.</span><span class=\"token function\">send</span><span class=\"token punctuation\">(</span>\n        <span class=\"token string\">'&lt;!doctype html>&lt;p>Loading...&lt;/p>&lt;script src=\"clientrender.js\">&lt;/script>'</span>\n      <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">onAllReady</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token comment\">// If you don't want streaming, use this instead of onShellReady.</span>\n      <span class=\"token comment\">// This will fire after the entire page content is ready.</span>\n      <span class=\"token comment\">// You can use this for crawlers or static generation.</span>\n\n      <span class=\"token comment\">// res.statusCode = didError ? 500 : 200;</span>\n      <span class=\"token comment\">// res.setHeader('Content-type', 'text/html');</span>\n      <span class=\"token comment\">// stream.pipe(res);</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function\">onError</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">err</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      didError <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n      console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>err<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>See the <a href=\"https://github.com/facebook/react/blob/14c2be8dac2d5482fda8a0906a31d239df8551fc/packages/react-dom/src/server/ReactDOMFizzServerNode.js#L36-L46\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">full list of options</a>.</p>\n<blockquote>\n<p>Note:</p>\n<p>This is a Node.js-specific API. Environments with <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Streams_API\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Web Streams</a>, like Deno and modern edge runtimes, should use <a href=\"#rendertoreadablestream\"><code class=\"gatsby-code-text\">renderToReadableStream</code></a> instead.</p>\n</blockquote>\n<hr>\n<h3 id=\"rendertoreadablestream\"><a href=\"#rendertoreadablestream\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code class=\"gatsby-code-text\">renderToReadableStream()</code> </h3>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\">ReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToReadableStream</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Streams a React element to its initial HTML. Returns a Promise that resolves to a <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Readable Stream</a>. Fully supports Suspense and streaming of HTML. <a href=\"https://github.com/reactwg/react-18/discussions/127\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Read more</a></p>\n<p>If you call <a href=\"/docs/react-dom-client.html#hydrateroot\"><code class=\"gatsby-code-text\">ReactDOM.hydrateRoot()</code></a> on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token keyword\">let</span> controller <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">AbortController</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">let</span> didError <span class=\"token operator\">=</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">try</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> stream <span class=\"token operator\">=</span> <span class=\"token keyword\">await</span> <span class=\"token function\">renderToReadableStream</span><span class=\"token punctuation\">(</span>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>html</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n      </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>body</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">Success</span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>body</span><span class=\"token punctuation\">></span></span><span class=\"token plain-text\">\n    </span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>html</span><span class=\"token punctuation\">></span></span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">signal</span><span class=\"token operator\">:</span> controller<span class=\"token punctuation\">.</span>signal<span class=\"token punctuation\">,</span>\n      <span class=\"token function\">onError</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n        didError <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span>\n        console<span class=\"token punctuation\">.</span><span class=\"token function\">error</span><span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  \n  <span class=\"token comment\">// This is to wait for all Suspense boundaries to be ready. You can uncomment</span>\n  <span class=\"token comment\">// this line if you want to buffer the entire HTML instead of streaming it.</span>\n  <span class=\"token comment\">// You can use this for crawlers or static generation:</span>\n\n  <span class=\"token comment\">// await stream.allReady;</span>\n\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Response</span><span class=\"token punctuation\">(</span>stream<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">status</span><span class=\"token operator\">:</span> didError <span class=\"token operator\">?</span> <span class=\"token number\">500</span> <span class=\"token operator\">:</span> <span class=\"token number\">200</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">headers</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token string-property property\">'Content-Type'</span><span class=\"token operator\">:</span> <span class=\"token string\">'text/html'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span> <span class=\"token keyword\">catch</span> <span class=\"token punctuation\">(</span>error<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">return</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Response</span><span class=\"token punctuation\">(</span>\n    <span class=\"token string\">'&lt;!doctype html>&lt;p>Loading...&lt;/p>&lt;script src=\"clientrender.js\">&lt;/script>'</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">{</span>\n      <span class=\"token literal-property property\">status</span><span class=\"token operator\">:</span> <span class=\"token number\">500</span><span class=\"token punctuation\">,</span>\n      <span class=\"token literal-property property\">headers</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token string-property property\">'Content-Type'</span><span class=\"token operator\">:</span> <span class=\"token string\">'text/html'</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>See the <a href=\"https://github.com/facebook/react/blob/14c2be8dac2d5482fda8a0906a31d239df8551fc/packages/react-dom/src/server/ReactDOMFizzServerBrowser.js#L27-L35\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">full list of options</a>.</p>\n<blockquote>\n<p>Note:</p>\n<p>This API depends on <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Streams_API\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Web Streams</a>. For Node.js, use <a href=\"#rendertopipeablestream\"><code class=\"gatsby-code-text\">renderToPipeableStream</code></a> instead.</p>\n</blockquote>\n<hr>\n<h3 id=\"rendertonodestream\"><a href=\"#rendertonodestream\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code class=\"gatsby-code-text\">renderToNodeStream()</code>  (Deprecated) </h3>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\">ReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToNodeStream</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Render a React element to its initial HTML. Returns a <a href=\"https://nodejs.org/api/stream.html#stream_readable_streams\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Node.js Readable stream</a> that outputs an HTML string. The HTML output by this stream is exactly equal to what <a href=\"#rendertostring\"><code class=\"gatsby-code-text\">ReactDOMServer.renderToString</code></a> would return. You can use this method to generate HTML on the server and send the markup down on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.</p>\n<p>If you call <a href=\"/docs/react-dom-client.html#hydrateroot\"><code class=\"gatsby-code-text\">ReactDOM.hydrateRoot()</code></a> on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.</p>\n<blockquote>\n<p>Note:</p>\n<p>Server-only. This API is not available in the browser.</p>\n<p>The stream returned from this method will return a byte stream encoded in utf-8. If you need a stream in another encoding, take a look at a project like <a href=\"https://www.npmjs.com/package/iconv-lite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">iconv-lite</a>, which provides transform streams for transcoding text.</p>\n</blockquote>\n<hr>\n<h3 id=\"rendertostaticnodestream\"><a href=\"#rendertostaticnodestream\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code class=\"gatsby-code-text\">renderToStaticNodeStream()</code> </h3>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\">ReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToStaticNodeStream</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Similar to <a href=\"#rendertonodestream\"><code class=\"gatsby-code-text\">renderToNodeStream</code></a>, except this doesn’t create extra DOM attributes that React uses internally, such as <code class=\"gatsby-code-text\">data-reactroot</code>. This is useful if you want to use React as a simple static page generator, as stripping away the extra attributes can save some bytes.</p>\n<p>The HTML output by this stream is exactly equal to what <a href=\"#rendertostaticmarkup\"><code class=\"gatsby-code-text\">ReactDOMServer.renderToStaticMarkup</code></a> would return.</p>\n<p>If you plan to use React on the client to make the markup interactive, do not use this method. Instead, use <a href=\"#rendertonodestream\"><code class=\"gatsby-code-text\">renderToNodeStream</code></a> on the server and <a href=\"/docs/react-dom-client.html#hydrateroot\"><code class=\"gatsby-code-text\">ReactDOM.hydrateRoot()</code></a> on the client.</p>\n<blockquote>\n<p>Note:</p>\n<p>Server-only. This API is not available in the browser.</p>\n<p>The stream returned from this method will return a byte stream encoded in utf-8. If you need a stream in another encoding, take a look at a project like <a href=\"https://www.npmjs.com/package/iconv-lite\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">iconv-lite</a>, which provides transform streams for transcoding text.</p>\n</blockquote>\n<hr>\n<h3 id=\"rendertostring\"><a href=\"#rendertostring\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code class=\"gatsby-code-text\">renderToString()</code> </h3>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\">ReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToString</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Render a React element to its initial HTML. React will return an HTML string. You can use this method to generate HTML on the server and send the markup down on the initial request for faster page loads and to allow search engines to crawl your pages for SEO purposes.</p>\n<p>If you call <a href=\"/docs/react-dom-client.html#hydrateroot\"><code class=\"gatsby-code-text\">ReactDOM.hydrateRoot()</code></a> on a node that already has this server-rendered markup, React will preserve it and only attach event handlers, allowing you to have a very performant first-load experience.</p>\n<blockquote>\n<p>Note</p>\n<p>This API has limited Suspense support and does not support streaming.</p>\n<p>On the server, it is recommended to use either <a href=\"#rendertopipeablestream\"><code class=\"gatsby-code-text\">renderToPipeableStream</code></a> (for Node.js) or <a href=\"#rendertoreadablestream\"><code class=\"gatsby-code-text\">renderToReadableStream</code></a> (for Web Streams) instead.</p>\n</blockquote>\n<hr>\n<h3 id=\"rendertostaticmarkup\"><a href=\"#rendertostaticmarkup\" aria-hidden class=\"anchor\"><svg aria-hidden=\"true\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a><code class=\"gatsby-code-text\">renderToStaticMarkup()</code> </h3>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\">ReactDOMServer<span class=\"token punctuation\">.</span><span class=\"token function\">renderToStaticMarkup</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span></code></pre></div>\n<p>Similar to <a href=\"#rendertostring\"><code class=\"gatsby-code-text\">renderToString</code></a>, except this doesn’t create extra DOM attributes that React uses internally, such as <code class=\"gatsby-code-text\">data-reactroot</code>. This is useful if you want to use React as a simple static page generator, as stripping away the extra attributes can save some bytes.</p>\n<p>If you plan to use React on the client to make the markup interactive, do not use this method. Instead, use <a href=\"#rendertostring\"><code class=\"gatsby-code-text\">renderToString</code></a> on the server and <a href=\"/docs/react-dom-client.html#hydrateroot\"><code class=\"gatsby-code-text\">ReactDOM.hydrateRoot()</code></a> on the client.</p>","frontmatter":{"title":"ReactDOMServer","next":null,"prev":null},"fields":{"path":"content/docs/reference-react-dom-server.md","slug":"docs/react-dom-server.html"}}},"pageContext":{"slug":"docs/react-dom-server.html"}},"staticQueryHashes":[]}