<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>React-18 on David Lang</title>
    <link>https://www.davidlang.tech/tags/react-18/</link>
    <description>Recent content in React-18 on David Lang</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sat, 15 Jan 2022 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://www.davidlang.tech/tags/react-18/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>React 18: Concurrent Features and the New Root API</title>
      <link>https://www.davidlang.tech/posts/react-18-concurrent-features-and-the-new-root-api/</link>
      <pubDate>Sat, 15 Jan 2022 00:00:00 +0000</pubDate>
      <guid>https://www.davidlang.tech/posts/react-18-concurrent-features-and-the-new-root-api/</guid>
      <description>&lt;p&gt;React 18 introduced concurrent rendering, automatic batching, and a new root API. These changes improve perceived performance without rewriting your entire app.&lt;/p&gt;&#xA;&lt;h2 id=&#34;createroot&#34;&gt;createRoot&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-jsx&#34; data-lang=&#34;jsx&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;import&lt;/span&gt; { createRoot } from &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;react-dom/client&amp;#39;&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;import&lt;/span&gt; App from &lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;./App&amp;#39;&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;const&lt;/span&gt; root &lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt; createRoot(&lt;span style=&#34;color:#b58900&#34;&gt;document&lt;/span&gt;.getElementById(&lt;span style=&#34;color:#2aa198&#34;&gt;&amp;#39;root&amp;#39;&lt;/span&gt;));&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;root.render(&amp;lt;&lt;span style=&#34;color:#268bd2&#34;&gt;App&lt;/span&gt; /&amp;gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The legacy &lt;code&gt;ReactDOM.render&lt;/code&gt; is deprecated. &lt;code&gt;createRoot&lt;/code&gt; enables concurrent features.&lt;/p&gt;&#xA;&lt;h2 id=&#34;suspense-and-transitions&#34;&gt;Suspense and Transitions&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;useTransition&lt;/code&gt; marks updates as non-urgent-keeping the UI responsive during heavy re-renders:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#93a1a1;background-color:#002b36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-jsx&#34; data-lang=&#34;jsx&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;const&lt;/span&gt; [isPending, startTransition] &lt;span style=&#34;color:#719e07&#34;&gt;=&lt;/span&gt; useTransition();&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#268bd2&#34;&gt;function&lt;/span&gt; handleTab(tab) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  startTransition(() =&amp;gt; setActiveTab(tab));&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;strict-mode-changes&#34;&gt;Strict Mode Changes&lt;/h2&gt;&#xA;&lt;p&gt;Strict Mode double-invokes effects in development to surface side-effect bugs. Audit &lt;code&gt;useEffect&lt;/code&gt; cleanup functions before upgrading.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
