{"componentChunkName":"component---src-templates-blog-js","path":"/blog/2022/03/08/react-18-upgrade-guide.html","result":{"data":{"markdownRemark":{"html":"<p>As we shared in the <a href=\"/blog/2022/03/29/react-v18.html\">release post</a>, React 18 introduces features powered by our new concurrent renderer, with a gradual adoption strategy for existing applications. In this post, we will guide you through the steps for upgrading to React 18.</p>\n<p>Please <a href=\"https://github.com/facebook/react/issues/new/choose\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">report any issues</a> you encounter while upgrading to React 18.</p>\n<p><em>Note for React Native users: React 18 will ship in a future version of React Native. This is because React 18 relies on the New React Native Architecture to benefit from the new capabilities presented in this blogpost. For more information, see the <a href=\"https://www.youtube.com/watch?v=FZ0cG47msEk&#x26;t=1530s\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">React Conf keynote here</a>.</em></p>\n<h2 id=\"installing\"><a href=\"#installing\" 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>Installing </h2>\n<p>To install the latest version of React:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"gatsby-code-bash\"><code class=\"gatsby-code-bash\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span> react react-dom</code></pre></div>\n<p>Or if you’re using yarn:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"gatsby-code-bash\"><code class=\"gatsby-code-bash\"><span class=\"token function\">yarn</span> <span class=\"token function\">add</span> react react-dom</code></pre></div>\n<h2 id=\"updates-to-client-rendering-apis\"><a href=\"#updates-to-client-rendering-apis\" 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>Updates to Client Rendering APIs </h2>\n<p>When you first install React 18, you will see a warning in the console:</p>\n<blockquote>\n<p>ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it’s running React 17. Learn more: <a href=\"https://reactjs.org/link/switch-to-createroot\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://reactjs.org/link/switch-to-createroot</a></p>\n</blockquote>\n<p>React 18 introduces a new root API which provides better ergonomics for managing roots. The new root API also enables the new concurrent renderer, which allows you to opt-into concurrent features.</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token comment\">// Before</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> render <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> container <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><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 attr-name\">tab</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>home<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span> container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// After</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> createRoot <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom/client'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> container <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<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> <span class=\"token comment\">// createRoot(container!) if you use TypeScript</span>\nroot<span class=\"token punctuation\">.</span><span class=\"token function\">render</span><span class=\"token punctuation\">(</span><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 attr-name\">tab</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>home<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>We’ve also changed <code class=\"gatsby-code-text\">unmountComponentAtNode</code> to <code class=\"gatsby-code-text\">root.unmount</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token comment\">// Before</span>\n<span class=\"token function\">unmountComponentAtNode</span><span class=\"token punctuation\">(</span>container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// After</span>\nroot<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<p>We’ve also removed the callback from render, since it usually does not have the expected result when using Suspense:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token comment\">// Before</span>\n<span class=\"token keyword\">const</span> container <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">render</span><span class=\"token punctuation\">(</span><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 attr-name\">tab</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>home<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span> container<span class=\"token punctuation\">,</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'rendered'</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\n<span class=\"token comment\">// After</span>\n<span class=\"token keyword\">function</span> <span class=\"token function\">AppWithCallbackAfterRender</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">useEffect</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span><span class=\"token string\">'rendered'</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\n  <span class=\"token keyword\">return</span> <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 attr-name\">tab</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>home<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">const</span> container <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<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><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span><span class=\"token class-name\">AppWithCallbackAfterRender</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<blockquote>\n<p>Note:</p>\n<p>There is no one-to-one replacement for the old render callback API — it depends on your use case. See the working group post for <a href=\"https://github.com/reactwg/react-18/discussions/5\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Replacing render with createRoot</a> for more information.</p>\n</blockquote>\n<p>Finally, if your app uses server-side rendering with hydration, upgrade <code class=\"gatsby-code-text\">hydrate</code> to <code class=\"gatsby-code-text\">hydrateRoot</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token comment\">// Before</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> hydrate <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> container <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token function\">hydrate</span><span class=\"token punctuation\">(</span><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 attr-name\">tab</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>home<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">,</span> container<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">// After</span>\n<span class=\"token keyword\">import</span> <span class=\"token punctuation\">{</span> hydrateRoot <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom/client'</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> container <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'app'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> root <span class=\"token operator\">=</span> <span class=\"token function\">hydrateRoot</span><span class=\"token punctuation\">(</span>container<span class=\"token punctuation\">,</span> <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 attr-name\">tab</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>home<span class=\"token punctuation\">\"</span></span> <span class=\"token punctuation\">/></span></span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token comment\">// Unlike with createRoot, you don't need a separate root.render() call here.</span></code></pre></div>\n<p>For more information, see the <a href=\"https://github.com/reactwg/react-18/discussions/5\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">working group discussion here</a>.</p>\n<blockquote>\n<p>Note</p>\n<p><strong>If your app doesn’t work after upgrading, check whether it’s wrapped in <code class=\"gatsby-code-text\">&lt;StrictMode></code>.</strong> <a href=\"#updates-to-strict-mode\">Strict Mode has gotten stricter in React 18</a>, and not all your components may be resilient to the new checks it adds in development mode. If removing Strict Mode fixes your app, you can remove it during the upgrade, and then add it back (either at the top or for a part of the tree) after you fix the issues that it’s pointing out.</p>\n</blockquote>\n<h2 id=\"updates-to-server-rendering-apis\"><a href=\"#updates-to-server-rendering-apis\" 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>Updates to Server Rendering APIs </h2>\n<p>In this release, we’re revamping our <code class=\"gatsby-code-text\">react-dom/server</code> APIs to fully support Suspense on the server and Streaming SSR. As part of these changes, we’re deprecating the old Node streaming API, which does not support incremental Suspense streaming on the server.</p>\n<p>Using this API will now warn:</p>\n<ul>\n<li><code class=\"gatsby-code-text\">renderToNodeStream</code>: <strong>Deprecated ⛔️️</strong></li>\n</ul>\n<p>Instead, for streaming in Node environments, use:</p>\n<ul>\n<li><code class=\"gatsby-code-text\">renderToPipeableStream</code>: <strong>New ✨</strong></li>\n</ul>\n<p>We’re also introducing a new API to support streaming SSR with Suspense for modern edge runtime environments, such as Deno and Cloudflare workers:</p>\n<ul>\n<li><code class=\"gatsby-code-text\">renderToReadableStream</code>: <strong>New ✨</strong></li>\n</ul>\n<p>The following APIs will continue working, but with limited support for Suspense:</p>\n<ul>\n<li><code class=\"gatsby-code-text\">renderToString</code>: <strong>Limited</strong> ⚠️</li>\n<li><code class=\"gatsby-code-text\">renderToStaticMarkup</code>: <strong>Limited</strong> ⚠️</li>\n</ul>\n<p>Finally, this API will continue to work for rendering e-mails:</p>\n<ul>\n<li><code class=\"gatsby-code-text\">renderToStaticNodeStream</code></li>\n</ul>\n<p>For more information on the changes to server rendering APIs, see the working group post on <a href=\"https://github.com/reactwg/react-18/discussions/22\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Upgrading to React 18 on the server</a>, a <a href=\"https://github.com/reactwg/react-18/discussions/37\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">deep dive on the new Suspense SSR Architecture</a>, and <a href=\"https://twitter.com/shaundai\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Shaundai Person’s</a> talk on <a href=\"https://www.youtube.com/watch?v=pj5N-Khihgc\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Streaming Server Rendering with Suspense</a> at React Conf 2021.</p>\n<h2 id=\"updates-to-typescript-definitions\"><a href=\"#updates-to-typescript-definitions\" 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>Updates to TypeScript definitions</h2>\n<p>If your project uses TypeScript, you will need to update your <code class=\"gatsby-code-text\">@types/react</code> and <code class=\"gatsby-code-text\">@types/react-dom</code> dependencies to the latest versions. The new types are safer and catch issues that used to be ignored by the type checker. The most notable change is that the <code class=\"gatsby-code-text\">children</code> prop now needs to be listed explicitly when defining props, for example:</p>\n<div class=\"gatsby-highlight has-highlighted-lines\" data-language=\"typescript\"><pre class=\"gatsby-code-typescript\"><code class=\"gatsby-code-typescript\"><span class=\"token keyword\">interface</span> <span class=\"token class-name\">MyButtonProps</span> <span class=\"token punctuation\">{</span>\n  color<span class=\"token operator\">:</span> <span class=\"token builtin\">string</span><span class=\"token punctuation\">;</span>\n<span class=\"gatsby-highlight-code-line\">  children<span class=\"token operator\">?</span><span class=\"token operator\">:</span> React<span class=\"token punctuation\">.</span>ReactNode<span class=\"token punctuation\">;</span></span><span class=\"token punctuation\">}</span></code></pre></div>\n<p>See the <a href=\"https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56210\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">React 18 typings pull request</a> for a full list of type-only changes. It links to example fixes in library types so you can see how to adjust your code. You can use the <a href=\"https://github.com/eps1lon/types-react-codemod\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">automated migration script</a> to help port your application code to the new and safer typings faster.</p>\n<p>If you find a bug in the typings, please <a href=\"https://github.com/DefinitelyTyped/DefinitelyTyped/discussions/new?category=issues-with-a-types-package\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">file an issue</a> in the DefinitelyTyped repo.</p>\n<h2 id=\"automatic-batching\"><a href=\"#automatic-batching\" 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>Automatic Batching </h2>\n<p>React 18 adds out-of-the-box performance improvements by doing more batching by default. Batching is when React groups multiple state updates into a single re-render for better performance. Before React 18, we only batched updates inside React event handlers. Updates inside of promises, setTimeout, native event handlers, or any other event were not batched in React by default:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token comment\">// Before React 18 only React events were batched</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setCount</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span> <span class=\"token operator\">=></span> c <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">setFlag</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">f</span> <span class=\"token operator\">=></span> <span class=\"token operator\">!</span>f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token comment\">// React will only re-render once at the end (that's batching!)</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setCount</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span> <span class=\"token operator\">=></span> c <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">setFlag</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">f</span> <span class=\"token operator\">=></span> <span class=\"token operator\">!</span>f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token comment\">// React will render twice, once for each state update (no batching)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>Starting in React 18 with <code class=\"gatsby-code-text\">createRoot</code>, all updates will be automatically batched, no matter where they originate from. This means that updates inside of timeouts, promises, native event handlers or any other event will batch the same way as updates inside of React events:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token comment\">// After React 18 updates inside of timeouts, promises,</span>\n<span class=\"token comment\">// native event handlers or any other event are batched.</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setCount</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span> <span class=\"token operator\">=></span> c <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">setFlag</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">f</span> <span class=\"token operator\">=></span> <span class=\"token operator\">!</span>f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token comment\">// React will only re-render once at the end (that's batching!)</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token function\">setTimeout</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">setCount</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span> <span class=\"token operator\">=></span> c <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token function\">setFlag</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">f</span> <span class=\"token operator\">=></span> <span class=\"token operator\">!</span>f<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token comment\">// React will only re-render once at the end (that's batching!)</span>\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>This is a breaking change, but we expect this to result in less work rendering, and therefore better performance in your applications. To opt-out of automatic batching, you can use <code class=\"gatsby-code-text\">flushSync</code>:</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 punctuation\">{</span> flushSync <span class=\"token punctuation\">}</span> <span class=\"token keyword\">from</span> <span class=\"token string\">'react-dom'</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">handleClick</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token function\">flushSync</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setCounter</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">c</span> <span class=\"token operator\">=></span> c <span class=\"token operator\">+</span> <span class=\"token number\">1</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 comment\">// React has updated the DOM by now</span>\n  <span class=\"token function\">flushSync</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n    <span class=\"token function\">setFlag</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">f</span> <span class=\"token operator\">=></span> <span class=\"token operator\">!</span>f<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 comment\">// React has updated the DOM by now</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>For more information, see the <a href=\"https://github.com/reactwg/react-18/discussions/21\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Automatic batching deep dive</a>.</p>\n<h2 id=\"new-apis-for-libraries\"><a href=\"#new-apis-for-libraries\" 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>New APIs for Libraries </h2>\n<p>In the React 18 Working Group we worked with library maintainers to create new APIs needed to support concurrent rendering for use cases specific to their use case in areas like styles, and external stores. To support React 18, some libraries may need to switch to one of the following APIs:</p>\n<ul>\n<li><code class=\"gatsby-code-text\">useSyncExternalStore</code> is a new hook that allows external stores to support concurrent reads by forcing updates to the store to be synchronous. This new API is recommended for any library that integrates with state external to React. For more information, see the <a href=\"https://github.com/reactwg/react-18/discussions/70\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">useSyncExternalStore overview post</a> and <a href=\"https://github.com/reactwg/react-18/discussions/86\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">useSyncExternalStore API details</a>.</li>\n<li><code class=\"gatsby-code-text\">useInsertionEffect</code> is a new hook that allows CSS-in-JS libraries to address performance issues of injecting styles in render. Unless you’ve already built a CSS-in-JS library we don’t expect you to ever use this. This hook will run after the DOM is mutated, but before layout effects read the new layout. This solves an issue that already exists in React 17 and below, but is even more important in React 18 because React yields to the browser during concurrent rendering, giving it a chance to recalculate layout. For more information, see the <a href=\"https://github.com/reactwg/react-18/discussions/110\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Library Upgrade Guide for <code class=\"gatsby-code-text\">&lt;style></code></a>.</li>\n</ul>\n<p>React 18 also introduces new APIs for concurrent rendering such as <code class=\"gatsby-code-text\">startTransition</code>, <code class=\"gatsby-code-text\">useDeferredValue</code> and <code class=\"gatsby-code-text\">useId</code>, which we share more about in the <a href=\"/blog/2022/03/29/react-v18.html\">release post</a>.</p>\n<h2 id=\"updates-to-strict-mode\"><a href=\"#updates-to-strict-mode\" 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>Updates to Strict Mode </h2>\n<p>In the future, we’d like to add a feature that allows React to add and remove sections of the UI while preserving state. For example, when a user tabs away from a screen and back, React should be able to immediately show the previous screen. To do this, React would unmount and remount trees using the same component state as before.</p>\n<p>This feature will give React better performance out-of-the-box, but requires components to be resilient to effects being mounted and destroyed multiple times. Most effects will work without any changes, but some effects assume they are only mounted or destroyed once.</p>\n<p>To help surface these issues, React 18 introduces a new development-only check to Strict Mode. This new check will automatically unmount and remount every component, whenever a component mounts for the first time, restoring the previous state on the second mount.</p>\n<p>Before this change, React would mount the component and create the effects:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"gatsby-code-text\"><code class=\"gatsby-code-text\">* React mounts the component.\n    * Layout effects are created.\n    * Effect effects are created.</code></pre></div>\n<p>With Strict Mode in React 18, React will simulate unmounting and remounting the component in development mode:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"gatsby-code-text\"><code class=\"gatsby-code-text\">* React mounts the component.\n    * Layout effects are created.\n    * Effect effects are created.\n* React simulates unmounting the component.\n    * Layout effects are destroyed.\n    * Effects are destroyed.\n* React simulates mounting the component with the previous state.\n    * Layout effect setup code runs\n    * Effect setup code runs</code></pre></div>\n<p>For more information, see the Working Group posts for <a href=\"https://github.com/reactwg/react-18/discussions/19\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Adding Reusable State to StrictMode</a> and <a href=\"https://github.com/reactwg/react-18/discussions/18\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">How to support Reusable State in Effects</a>.</p>\n<h2 id=\"configuring-your-testing-environment\"><a href=\"#configuring-your-testing-environment\" 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>Configuring Your Testing Environment </h2>\n<p>When you first update your tests to use <code class=\"gatsby-code-text\">createRoot</code>, you may see this warning in your test console:</p>\n<blockquote>\n<p>The current testing environment is not configured to support act(…)</p>\n</blockquote>\n<p>To fix this, set <code class=\"gatsby-code-text\">globalThis.IS_REACT_ACT_ENVIRONMENT</code> to <code class=\"gatsby-code-text\">true</code> before running your test:</p>\n<div class=\"gatsby-highlight\" data-language=\"jsx\"><pre class=\"gatsby-code-jsx\"><code class=\"gatsby-code-jsx\"><span class=\"token comment\">// In your test setup file</span>\nglobalThis<span class=\"token punctuation\">.</span><span class=\"token constant\">IS_REACT_ACT_ENVIRONMENT</span> <span class=\"token operator\">=</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">;</span></code></pre></div>\n<p>The purpose of the flag is to tell React that it’s running in a unit test-like environment. React will log helpful warnings if you forget to wrap an update with <code class=\"gatsby-code-text\">act</code>.</p>\n<p>You can also set the flag to <code class=\"gatsby-code-text\">false</code> to tell React that <code class=\"gatsby-code-text\">act</code> isn’t needed. This can be useful for end-to-end tests that simulate a full browser environment.</p>\n<p>Eventually, we expect testing libraries will configure this for you automatically. For example, the <a href=\"https://github.com/testing-library/react-testing-library/issues/509#issuecomment-917989936\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">next version of React Testing Library has built-in support for React 18</a> without any additional configuration.</p>\n<p><a href=\"https://github.com/reactwg/react-18/discussions/102\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">More background on the <code class=\"gatsby-code-text\">act</code> testing API and related changes</a> is available in the working group.</p>\n<h2 id=\"dropping-support-for-internet-explorer\"><a href=\"#dropping-support-for-internet-explorer\" 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>Dropping Support for Internet Explorer </h2>\n<p>In this release, React is dropping support for Internet Explorer, which is <a href=\"https://blogs.windows.com/windowsexperience/2021/05/19/the-future-of-internet-explorer-on-windows-10-is-in-microsoft-edge\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">going out of support on June 15, 2022</a>. We’re making this change now because new features introduced in React 18 are built using modern browser features such as microtasks which cannot be adequately polyfilled in IE.</p>\n<p>If you need to support Internet Explorer we recommend you stay with React 17.</p>\n<h2 id=\"deprecations\"><a href=\"#deprecations\" 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>Deprecations </h2>\n<ul>\n<li><code class=\"gatsby-code-text\">react-dom</code>: <code class=\"gatsby-code-text\">ReactDOM.render</code> has been deprecated. Using it will warn and run your app in React 17 mode.</li>\n<li><code class=\"gatsby-code-text\">react-dom</code>: <code class=\"gatsby-code-text\">ReactDOM.hydrate</code> has been deprecated. Using it will warn and run your app in React 17 mode.</li>\n<li><code class=\"gatsby-code-text\">react-dom</code>: <code class=\"gatsby-code-text\">ReactDOM.unmountComponentAtNode</code> has been deprecated.</li>\n<li><code class=\"gatsby-code-text\">react-dom</code>: <code class=\"gatsby-code-text\">ReactDOM.renderSubtreeIntoContainer</code> has been deprecated.</li>\n<li><code class=\"gatsby-code-text\">react-dom/server</code>: <code class=\"gatsby-code-text\">ReactDOMServer.renderToNodeStream</code> has been deprecated.</li>\n</ul>\n<h2 id=\"other-breaking-changes\"><a href=\"#other-breaking-changes\" 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>Other Breaking Changes </h2>\n<ul>\n<li><strong>Consistent useEffect timing</strong>: React now always synchronously flushes effect functions if the update was triggered during a discrete user input event such as a click or a keydown event. Previously, the behavior wasn’t always predictable or consistent.</li>\n<li><strong>Stricter hydration errors</strong>: Hydration mismatches due to missing or extra text content are now treated like errors instead of warnings. React will no longer attempt to “patch up” individual nodes by inserting or deleting a node on the client in an attempt to match the server markup, and will revert to client rendering up to the closest <code class=\"gatsby-code-text\">&lt;Suspense></code> boundary in the tree. This ensures the hydrated tree is consistent and avoids potential privacy and security holes that can be caused by hydration mismatches.</li>\n<li><strong>Suspense trees are always consistent:</strong> If a component suspends before it’s fully added to the tree, React will not add it to the tree in an incomplete state or fire its effects. Instead, React will throw away the new tree completely, wait for the asynchronous operation to finish, and then retry rendering again from scratch. React will render the retry attempt concurrently, and without blocking the browser.</li>\n<li><strong>Layout Effects with Suspense</strong>: When a tree re-suspends and reverts to a fallback, React will now clean up layout effects, and then re-create them when the content inside the boundary is shown again. This fixes an issue which prevented component libraries from correctly measuring layout when used with Suspense.</li>\n<li><strong>New JS Environment Requirements</strong>: React now depends on modern browsers features including <code class=\"gatsby-code-text\">Promise</code>, <code class=\"gatsby-code-text\">Symbol</code>, and <code class=\"gatsby-code-text\">Object.assign</code>. If you support older browsers and devices such as Internet Explorer which do not provide modern browser features natively or have non-compliant implementations, consider including a global polyfill in your bundled application.</li>\n</ul>\n<h2 id=\"other-notable-changes\"><a href=\"#other-notable-changes\" 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>Other Notable Changes </h2>\n<h3 id=\"react\"><a href=\"#react\" 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>React </h3>\n<ul>\n<li><strong>Components can now render <code class=\"gatsby-code-text\">undefined</code>:</strong> React no longer warns if you return <code class=\"gatsby-code-text\">undefined</code> from a component. This makes the allowed component return values consistent with values that are allowed in the middle of a component tree. We suggest to use a linter to prevent mistakes like forgetting a <code class=\"gatsby-code-text\">return</code> statement before JSX.</li>\n<li><strong>In tests, <code class=\"gatsby-code-text\">act</code> warnings are now opt-in:</strong> If you’re running end-to-end tests, the <code class=\"gatsby-code-text\">act</code> warnings are unnecessary. We’ve introduced an <a href=\"https://github.com/reactwg/react-18/discussions/102\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">opt-in</a> mechanism so you can enable them only for unit tests where they are useful and beneficial.</li>\n<li><strong>No warning about <code class=\"gatsby-code-text\">setState</code> on unmounted components:</strong> Previously, React warned about memory leaks when you call <code class=\"gatsby-code-text\">setState</code> on an unmounted component. This warning was added for subscriptions, but people primarily run into it in scenarios where setting state is fine, and workarounds make the code worse. We’ve <a href=\"https://github.com/facebook/react/pull/22114\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">removed</a> this warning.</li>\n<li><strong>No suppression of console logs:</strong> When you use Strict Mode, React renders each component twice to help you find unexpected side effects. In React 17, we’ve suppressed console logs for one of the two renders to make the logs easier to read. In response to <a href=\"https://github.com/facebook/react/issues/21783\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">community feedback</a> about this being confusing, we’ve removed the suppression. Instead, if you have React DevTools installed, the second log’s renders will be displayed in grey, and there will be an option (off by default) to suppress them completely.</li>\n<li><strong>Improved memory usage:</strong> React now cleans up more internal fields on unmount, making the impact from unfixed memory leaks that may exist in your application code less severe.</li>\n</ul>\n<h3 id=\"react-dom-server\"><a href=\"#react-dom-server\" 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>React DOM Server </h3>\n<ul>\n<li><strong><code class=\"gatsby-code-text\">renderToString</code>:</strong> Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest <code class=\"gatsby-code-text\">&lt;Suspense></code> boundary and then retry rendering the same content on the client. It is still recommended that you switch to a streaming API like <code class=\"gatsby-code-text\">renderToPipeableStream</code> or <code class=\"gatsby-code-text\">renderToReadableStream</code> instead.</li>\n<li><strong><code class=\"gatsby-code-text\">renderToStaticMarkup</code>:</strong> Will no longer error when suspending on the server. Instead, it will emit the fallback HTML for the closest <code class=\"gatsby-code-text\">&lt;Suspense></code> boundary.</li>\n</ul>\n<h2 id=\"changelog\"><a href=\"#changelog\" 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>Changelog </h2>\n<p>You can view the <a href=\"https://github.com/facebook/react/blob/main/CHANGELOG.md\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">full changelog here</a>.</p>","excerpt":"As we shared in the release post, React 18 introduces features powered by our new concurrent renderer, with a gradual adoption strategy for existing applications. In this post, we will guide you through the steps for upgrading to React 18. Please report any issues you encounter while upgrading to React 18. Note for React Native users: React 18 will ship in a future version of React Native. This is because React 18 relies on the New React Native Architecture to benefit from the new capabilities…","frontmatter":{"title":"How to Upgrade to React 18","next":null,"prev":null,"author":[{"frontmatter":{"name":"Rick Hanlon","url":"https://twitter.com/rickhanlonii"}}]},"fields":{"date":"March 08, 2022","path":"content/blog/2022-03-08-react-18-upgrade-guide.md","slug":"/blog/2022/03/08/react-18-upgrade-guide.html"}},"allMarkdownRemark":{"edges":[{"node":{"frontmatter":{"title":"React Labs: What We've Been Working On – June 2022"},"fields":{"slug":"/blog/2022/06/15/react-labs-what-we-have-been-working-on-june-2022.html"}}},{"node":{"frontmatter":{"title":"React v18.0"},"fields":{"slug":"/blog/2022/03/29/react-v18.html"}}},{"node":{"frontmatter":{"title":"How to Upgrade to React 18"},"fields":{"slug":"/blog/2022/03/08/react-18-upgrade-guide.html"}}},{"node":{"frontmatter":{"title":"React Conf 2021 Recap"},"fields":{"slug":"/blog/2021/12/17/react-conf-2021-recap.html"}}},{"node":{"frontmatter":{"title":"The Plan for React 18"},"fields":{"slug":"/blog/2021/06/08/the-plan-for-react-18.html"}}},{"node":{"frontmatter":{"title":"Introducing Zero-Bundle-Size React Server Components"},"fields":{"slug":"/blog/2020/12/21/data-fetching-with-react-server-components.html"}}},{"node":{"frontmatter":{"title":"React v17.0"},"fields":{"slug":"/blog/2020/10/20/react-v17.html"}}},{"node":{"frontmatter":{"title":"Introducing the New JSX Transform"},"fields":{"slug":"/blog/2020/09/22/introducing-the-new-jsx-transform.html"}}},{"node":{"frontmatter":{"title":"React v17.0 Release Candidate: No New Features"},"fields":{"slug":"/blog/2020/08/10/react-v17-rc.html"}}},{"node":{"frontmatter":{"title":"React v16.13.0"},"fields":{"slug":"/blog/2020/02/26/react-v16.13.0.html"}}}]}},"pageContext":{"slug":"/blog/2022/03/08/react-18-upgrade-guide.html"}},"staticQueryHashes":[]}