{"componentChunkName":"component---src-templates-docs-js","path":"/docs/react-dom-client.html","result":{"data":{"markdownRemark":{"html":"<div class=\"scary\">\n<blockquote>\n<p>These docs are old and won’t be updated. Go to <a href=\"https://react.dev/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">react.dev</a> for the new React docs.</p>\n<p>These new documentation pages teach modern React:</p>\n<ul>\n<li><a href=\"https://react.dev/reference/react-dom/client\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><code class=\"gatsby-code-text\">react-dom</code>: Client APIs</a></li>\n</ul>\n</blockquote>\n</div>\n<p>The <code class=\"gatsby-code-text\">react-dom/client</code> package provides client-specific methods used for initializing an app on the client. Most of your components should not need to use this module.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token keyword\">import</span> <span class=\"token operator\">*</span> <span class=\"token keyword\">as</span> ReactDOM <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom/client'</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>If you use ES5 with npm, you can write:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token keyword\">var</span> ReactDOM <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'react-dom/client'</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>The following methods can be used in client environments:</p>\n<ul>\n<li><a href=\"#createroot\"><code class=\"gatsby-code-text\">createRoot()</code></a></li>\n<li><a href=\"#hydrateroot\"><code class=\"gatsby-code-text\">hydrateRoot()</code></a></li>\n</ul>\n<h3 id=\"browser-support\"><a href=\"#browser-support\" 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>Browser Support </h3>\n<p>React supports all modern browsers, although <a href=\"/docs/javascript-environment-requirements.html\">some polyfills are required</a> for older versions.</p>\n<blockquote>\n<p>Note</p>\n<p>We do not support older browsers that don’t support ES5 methods or microtasks such as Internet Explorer. You may find that your apps do work in older browsers if polyfills such as <a href=\"https://github.com/es-shims/es5-shim\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">es5-shim and es5-sham</a> are included in the page, but you’re on your own if you choose to take this path.</p>\n</blockquote>\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=\"createroot\"><a href=\"#createroot\" 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\">createRoot()</code> </h3>\n<div class=\"scary\">\n<blockquote>\n<p>This content is out of date.</p>\n<p>Read the new React documentation for <a href=\"https://react.dev/reference/react-dom/client/createRoot\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><code class=\"gatsby-code-text\">createRoot</code></a>.</p>\n</blockquote>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token function\">createRoot</span><span class=\"token punctuation\">(</span>container<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Create a React root for the supplied <code class=\"gatsby-code-text\">container</code> and return the root. The root can be used to render a React element into the DOM with <code class=\"gatsby-code-text\">render</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token keyword\">const</span> root <span class=\"token operator\">=</span> <span class=\"token function\">createRoot</span><span class=\"token punctuation\">(</span>container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nroot<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span>element<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p><code class=\"gatsby-code-text\">createRoot</code> accepts two options:</p>\n<ul>\n<li><code class=\"gatsby-code-text\">onRecoverableError</code>: optional callback called when React automatically recovers from errors.</li>\n<li><code class=\"gatsby-code-text\">identifierPrefix</code>: optional prefix React uses for ids generated by <code class=\"gatsby-code-text\">React.useId</code>. Useful to avoid conflicts when using multiple roots on the same page. Must be the same prefix used on the server.</li>\n</ul>\n<p>The root can also be unmounted with <code class=\"gatsby-code-text\">unmount</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\">root<span class=\"token punctuation\">.</span><span class=\"token function\">unmount</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p>Note:</p>\n<p><code class=\"gatsby-code-text\">createRoot()</code> controls the contents of the container node you pass in. Any existing DOM elements inside are replaced when render is called. Later calls use React’s DOM diffing algorithm for efficient updates.</p>\n<p><code class=\"gatsby-code-text\">createRoot()</code> does not modify the container node (only modifies the children of the container). It may be possible to insert a component to an existing DOM node without overwriting the existing children.</p>\n<p>Using <code class=\"gatsby-code-text\">createRoot()</code> to hydrate a server-rendered container is not supported. Use <a href=\"#hydrateroot\"><code class=\"gatsby-code-text\">hydrateRoot()</code></a> instead.</p>\n</blockquote>\n<hr>\n<h3 id=\"hydrateroot\"><a href=\"#hydrateroot\" 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\">hydrateRoot()</code> </h3>\n<div class=\"scary\">\n<blockquote>\n<p>This content is out of date.</p>\n<p>Read the new React documentation for <a href=\"https://react.dev/reference/react-dom/client/hydrateRoot\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><code class=\"gatsby-code-text\">hydrateRoot</code></a>.</p>\n</blockquote>\n</div>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token function\">hydrateRoot</span><span class=\"token punctuation\">(</span>container<span class=\"token punctuation\">,</span> element<span class=\"token punctuation\">[</span><span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>Same as <a href=\"#createroot\"><code class=\"gatsby-code-text\">createRoot()</code></a>, but is used to hydrate a container whose HTML contents were rendered by <a href=\"/docs/react-dom-server.html\"><code class=\"gatsby-code-text\">ReactDOMServer</code></a>. React will attempt to attach event listeners to the existing markup.</p>\n<p><code class=\"gatsby-code-text\">hydrateRoot</code> accepts two options:</p>\n<ul>\n<li><code class=\"gatsby-code-text\">onRecoverableError</code>: optional callback called when React automatically recovers from errors.</li>\n<li><code class=\"gatsby-code-text\">identifierPrefix</code>: optional prefix React uses for ids generated by <code class=\"gatsby-code-text\">React.useId</code>. Useful to avoid conflicts when using multiple roots on the same page. Must be the same prefix used on the server.</li>\n</ul>\n<blockquote>\n<p>Note</p>\n<p>React expects that the rendered content is identical between the server and the client. It can patch up differences in text content, but you should treat mismatches as bugs and fix them. In development mode, React warns about mismatches during hydration. There are no guarantees that attribute differences will be patched up in case of mismatches. This is important for performance reasons because in most apps, mismatches are rare, and so validating all markup would be prohibitively expensive.</p>\n</blockquote>","frontmatter":{"title":"ReactDOMClient","next":null,"prev":null},"fields":{"path":"content/docs/reference-react-dom-client.md","slug":"docs/react-dom-client.html"}}},"pageContext":{"slug":"docs/react-dom-client.html"}},"staticQueryHashes":[]}