<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Pascal Fong Kye</title>
    <description>The latest articles on Forem by Pascal Fong Kye (@pfongkye).</description>
    <link>https://forem.com/pfongkye</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F803293%2Fcf8b63e9-85ac-4abd-9eda-1a835b20d691.jpeg</url>
      <title>Forem: Pascal Fong Kye</title>
      <link>https://forem.com/pfongkye</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/pfongkye"/>
    <language>en</language>
    <item>
      <title>React 18 setTransition</title>
      <dc:creator>Pascal Fong Kye</dc:creator>
      <pubDate>Thu, 27 Jan 2022 09:06:47 +0000</pubDate>
      <link>https://forem.com/manomano-tech-team/react-18-settransition-4oop</link>
      <guid>https://forem.com/manomano-tech-team/react-18-settransition-4oop</guid>
      <description>&lt;h2&gt;
  
  
  startTransition
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/blog/2021/12/17/react-conf-2021-recap.html"&gt;React 18&lt;/a&gt; introduces a new concurrent feature called &lt;a href="https://github.com/reactwg/react-18/discussions/41"&gt;startTransition&lt;/a&gt; which aims to solve problems we tried to solve using &lt;a href="https://css-tricks.com/debouncing-throttling-explained-examples/"&gt;debounce and throttle&lt;/a&gt;, and much more.&lt;/p&gt;

&lt;p&gt;This &lt;a href="https://github.com/reactwg/react-18/discussions/65"&gt;thread&lt;/a&gt; gives a deep dive example of how it solves the problem of UI responsiveness when there is expensive computation taking place.&lt;/p&gt;

&lt;p&gt;Before React 18, we tend to use debounce (or throttle depending on the situation) to schedule this compute intensive task at a given time &lt;em&gt;T&lt;/em&gt; so that the UI feels more responsive to other events. But every time the task will start after &lt;em&gt;T&lt;/em&gt; has elapsed, even if it takes less time than &lt;em&gt;T&lt;/em&gt;. And the task will still occur as a whole chunk, blocking the thread during this time. &lt;/p&gt;

&lt;p&gt;This is where startTransition API brings a new approach to deal with these problems.&lt;br&gt;
It can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;split tasks into small chunks and be smart enough to let the browser process incoming events (mouse events for example) -&amp;gt; &lt;strong&gt;yielding&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;manage an urgent update in priority skipping pending ones -&amp;gt; &lt;strong&gt;interrupting&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;update using new state by disposing of unfinished task with stale state -&amp;gt; &lt;strong&gt;skipping old results&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Check my &lt;a href="https://nextjs-blog-pfongkye.vercel.app/"&gt;personal blog&lt;/a&gt; for more articles.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
