<?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>DEV Community: Shanthi's Dev Diary</title>
    <description>The latest articles on DEV Community by Shanthi's Dev Diary (@shantih_palani).</description>
    <link>https://dev.to/shantih_palani</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%2F1302602%2Ff068a6b7-1771-41a1-b353-a664ecda5e62.png</url>
      <title>DEV Community: Shanthi's Dev Diary</title>
      <link>https://dev.to/shantih_palani</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shantih_palani"/>
    <language>en</language>
    <item>
      <title>Web Components: The Most Underrated Feature of the Modern Web</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Sun, 15 Mar 2026 18:57:34 +0000</pubDate>
      <link>https://dev.to/shantih_palani/web-components-the-most-underrated-feature-of-the-modern-web-40cd</link>
      <guid>https://dev.to/shantih_palani/web-components-the-most-underrated-feature-of-the-modern-web-40cd</guid>
      <description>&lt;p&gt;A few days ago, one of my colleagues casually asked me:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Do you know Web Components?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;My immediate answer was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Yes, of course.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But a few seconds later I paused and thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Wait… what exactly are Web Components?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I had &lt;strong&gt;heard about them in tech talks&lt;/strong&gt;, maybe read about them somewhere, but I couldn’t confidently say:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I had used them in a project&lt;/li&gt;
&lt;li&gt;I fully understood how they worked&lt;/li&gt;
&lt;li&gt;I knew when to use them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That moment made me curious.&lt;/p&gt;

&lt;p&gt;So I started digging deeper… and realized something surprising:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web Components might be one of the most underrated features of the modern web.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  What Are Web Components?
&lt;/h2&gt;

&lt;p&gt;Web Components are a set of &lt;strong&gt;native browser APIs&lt;/strong&gt; that allow developers to create &lt;strong&gt;custom, reusable HTML elements&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of relying on framework-specific components like in React, Angular, or Vue, Web Components let you define your own HTML tags.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;user-card&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Shanthi"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/user-card&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once defined, the browser itself understands this component.&lt;/p&gt;

&lt;p&gt;That means the same component can work in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React apps&lt;/li&gt;
&lt;li&gt;Angular apps&lt;/li&gt;
&lt;li&gt;Vue apps&lt;/li&gt;
&lt;li&gt;Plain HTML pages&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Write once, use anywhere.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  The 4 Building Blocks of Web Components
&lt;/h2&gt;

&lt;p&gt;Web Components are built on four main browser standards.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Custom Elements
&lt;/h2&gt;

&lt;p&gt;Custom Elements allow you to create your own HTML tags.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UserCard&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;connectedCallback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;p&amp;gt;Hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/p&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user-card&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;UserCard&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the browser recognizes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;user-card&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Shanthi"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/user-card&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  2. Shadow DOM
&lt;/h2&gt;

&lt;p&gt;Shadow DOM provides &lt;strong&gt;encapsulation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Styles inside the component stay inside the component&lt;/li&gt;
&lt;li&gt;External CSS cannot break it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shadow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;shadow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
  &amp;lt;style&amp;gt;
    p { color: blue; }
  &amp;lt;/style&amp;gt;
  &amp;lt;p&amp;gt;Hello from Shadow DOM&amp;lt;/p&amp;gt;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Think of it like giving your component &lt;strong&gt;its own private DOM and CSS space&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. HTML Templates
&lt;/h2&gt;

&lt;p&gt;Templates allow you to define reusable HTML structures.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;template&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"cardTemplate"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"card"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript can clone this template whenever needed.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. ES Modules
&lt;/h2&gt;

&lt;p&gt;Web Components are usually distributed using &lt;strong&gt;JavaScript modules&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./user-card.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This keeps components &lt;strong&gt;modular and reusable across applications&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Simple Web Component Example
&lt;/h2&gt;

&lt;p&gt;Let’s build a small component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloWorld&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;connectedCallback&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Developer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
      &amp;lt;style&amp;gt;
        div {
          padding: 10px;
          border: 1px solid #ddd;
          border-radius: 6px;
        }
      &amp;lt;/style&amp;gt;
      &amp;lt;div&amp;gt;Hello &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; 👋&amp;lt;/div&amp;gt;
    `&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;customElements&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello-world&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;hello-world&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Shanthi"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/hello-world&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hello Shanthi 👋
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Why Web Components Matter
&lt;/h2&gt;

&lt;h2&gt;
  
  
  1. Framework Independence
&lt;/h2&gt;

&lt;p&gt;A single Web Component can work in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React&lt;/li&gt;
&lt;li&gt;Angular&lt;/li&gt;
&lt;li&gt;Vue&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is especially useful for organizations managing &lt;strong&gt;multiple frontend stacks&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Perfect for Design Systems
&lt;/h2&gt;

&lt;p&gt;Web Components are great for building &lt;strong&gt;design system libraries&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;company-button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;company-modal&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;company-card&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These can be reused across multiple applications without rewriting them for each framework.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Long-Term Stability
&lt;/h2&gt;

&lt;p&gt;Frameworks evolve quickly.&lt;/p&gt;

&lt;p&gt;But Web Components are &lt;strong&gt;browser standards&lt;/strong&gt;, meaning they will keep working regardless of which framework becomes popular next.&lt;/p&gt;




&lt;h2&gt;
  
  
  Fun Facts About Web Components
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🧠 Fun Fact #1
&lt;/h3&gt;

&lt;p&gt;Many developers &lt;strong&gt;use Web Components without realizing it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For example, the &lt;code&gt;&amp;lt;video&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;audio&amp;gt;&lt;/code&gt; elements behave like complex components built into the browser.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧠 Fun Fact #2
&lt;/h3&gt;

&lt;p&gt;Google was one of the early promoters of Web Components and created the &lt;strong&gt;Polymer library&lt;/strong&gt; to help developers adopt them.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧠 Fun Fact #3
&lt;/h3&gt;

&lt;p&gt;Salesforce built their UI framework called &lt;strong&gt;Lightning Web Components&lt;/strong&gt; using this concept.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧠 Fun Fact #4
&lt;/h3&gt;

&lt;p&gt;Many modern &lt;strong&gt;microfrontend architectures&lt;/strong&gt; use Web Components as a way to integrate applications built with different frameworks.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Aren’t Web Components More Popular?
&lt;/h2&gt;

&lt;p&gt;This was the question I kept asking myself.&lt;/p&gt;

&lt;p&gt;A few possible reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Framework ecosystems became dominant&lt;/li&gt;
&lt;li&gt;Earlier browser support was inconsistent&lt;/li&gt;
&lt;li&gt;Developers are more comfortable using framework-specific solutions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But things are changing.&lt;/p&gt;

&lt;p&gt;Modern browsers now fully support Web Components, and more teams are exploring them for &lt;strong&gt;design systems and cross-framework libraries&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;It’s funny how a simple question from a colleague made me revisit a concept I had only heard about in passing.&lt;/p&gt;

&lt;p&gt;Sometimes, technologies exist in the background for years before we truly notice their potential.&lt;/p&gt;

&lt;p&gt;Web Components might not be the most talked-about topic in frontend development, but they offer something powerful:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reusable UI components that work across frameworks.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And that makes them one of the &lt;strong&gt;most underrated features of the modern web.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;💡 &lt;strong&gt;Now I’m curious&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Have you used Web Components in production?&lt;/p&gt;

&lt;p&gt;Or are they still one of those technologies you’ve heard about but never explored deeply?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>webcomponents</category>
    </item>
    <item>
      <title>Understanding the &lt;Activity&gt; Component in React 19</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Wed, 21 Jan 2026 09:09:30 +0000</pubDate>
      <link>https://dev.to/shantih_palani/understanding-the-component-in-react-19-2k01</link>
      <guid>https://dev.to/shantih_palani/understanding-the-component-in-react-19-2k01</guid>
      <description>&lt;p&gt;React 19 continues to push the boundaries of UI performance and control. One of the quieter—but powerful—additions is the &lt;strong&gt;&lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; component&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At first glance, it looks like another conditional rendering helper. But under the hood, &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; solves a long-standing problem in React apps:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;hiding UI without destroying its state or effects&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s break it down.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤔 The Problem with Conditional Rendering
&lt;/h2&gt;

&lt;p&gt;In React today, hiding UI usually means &lt;strong&gt;unmounting it&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isVisible&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ChatWindow&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When &lt;code&gt;isVisible&lt;/code&gt; becomes &lt;code&gt;false&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The component unmounts&lt;/li&gt;
&lt;li&gt;State is lost&lt;/li&gt;
&lt;li&gt;Effects are cleaned up&lt;/li&gt;
&lt;li&gt;Timers, subscriptions, and caches reset&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is often &lt;em&gt;not&lt;/em&gt; what we want.&lt;/p&gt;




&lt;h2&gt;
  
  
  🆕 Enter &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; in React 19
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; component allows you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hide UI&lt;/li&gt;
&lt;li&gt;Keep it &lt;strong&gt;mounted&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Preserve &lt;strong&gt;state, effects, and subscriptions&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it as &lt;strong&gt;pausing visibility, not lifecycle&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  ✨ Basic Usage
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Activity&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Activity&lt;/span&gt; &lt;span class="na"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isVisible&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ChatWindow&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Activity&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What happens here?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;When &lt;code&gt;visible={false}&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;The UI is hidden&lt;/li&gt;
&lt;li&gt;The component stays mounted&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;When &lt;code&gt;visible={true}&lt;/code&gt;:

&lt;ul&gt;
&lt;li&gt;The UI reappears instantly&lt;/li&gt;
&lt;li&gt;State is preserved&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧠 How &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; Thinks
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Behavior&lt;/th&gt;
&lt;th&gt;Conditional Rendering&lt;/th&gt;
&lt;th&gt;&lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Component mounted&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;State preserved&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Effects retained&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UI visible&lt;/td&gt;
&lt;td&gt;Conditional&lt;/td&gt;
&lt;td&gt;Controlled&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🔥 Real-World Use Cases
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1️⃣ Tabbed Interfaces
&lt;/h3&gt;

&lt;p&gt;Switch tabs without losing form input or scroll position.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Activity&lt;/span&gt; &lt;span class="na"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;activeTab&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;profile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ProfileForm&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Activity&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  2️⃣ Modals &amp;amp; Drawers
&lt;/h3&gt;

&lt;p&gt;Avoid re-initializing data every time a modal opens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Activity&lt;/span&gt; &lt;span class="na"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isOpen&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SettingsModal&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Activity&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  3️⃣ Background UI
&lt;/h3&gt;

&lt;p&gt;Keep background widgets alive but invisible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Activity&lt;/span&gt; &lt;span class="na"&gt;visible&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;LiveSyncService&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Activity&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⚠️ Things to Keep in Mind
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; &lt;strong&gt;does not stop effects&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Background logic &lt;strong&gt;continues running&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Use carefully with:

&lt;ul&gt;
&lt;li&gt;Polling&lt;/li&gt;
&lt;li&gt;Intervals&lt;/li&gt;
&lt;li&gt;Heavy subscriptions&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;If you want effects to pause, you must handle that explicitly.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧩 &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; vs &lt;code&gt;Suspense&lt;/code&gt;
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Suspense&lt;/th&gt;
&lt;th&gt;Activity&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Handles async loading&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Controls visibility&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Preserves state&lt;/td&gt;
&lt;td&gt;⚠️ Partial&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Lifecycle remains&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;They solve &lt;strong&gt;different problems&lt;/strong&gt; and work well together.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Mental Model
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Suspense delays rendering.&lt;br&gt;&lt;br&gt;
Activity hides rendering.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🚀 Why This Matters
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; enables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Faster UI transitions&lt;/li&gt;
&lt;li&gt;Better UX&lt;/li&gt;
&lt;li&gt;Fewer unnecessary remounts&lt;/li&gt;
&lt;li&gt;More control over component lifecycles&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s a small API with &lt;strong&gt;big architectural implications&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏁 Final Thoughts
&lt;/h2&gt;

&lt;p&gt;React 19’s &lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; component is a step toward &lt;strong&gt;intentional UI lifecycles&lt;/strong&gt;—where visibility and existence are no longer the same thing.&lt;/p&gt;

&lt;p&gt;If you’ve ever wished for:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hide this component, but don’t reset it”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Activity&amp;gt;&lt;/code&gt; is your answer.&lt;/p&gt;




&lt;p&gt;💬 Have thoughts or use cases in mind?&lt;br&gt;&lt;br&gt;
Drop them in the comments—let’s discuss React 19 together.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>frontend</category>
      <category>react19</category>
    </item>
    <item>
      <title>Rethinking React Architecture at Scale: From Hooks to Remote Contexts With Code base</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Tue, 06 Jan 2026 19:34:09 +0000</pubDate>
      <link>https://dev.to/shantih_palani/rethinking-react-architecture-at-scale-from-hooks-to-remote-contexts-3a8j</link>
      <guid>https://dev.to/shantih_palani/rethinking-react-architecture-at-scale-from-hooks-to-remote-contexts-3a8j</guid>
      <description>&lt;p&gt;React hooks, the Context API, and Suspense have completely changed how we build modern React applications. For &lt;strong&gt;small to medium-sized apps&lt;/strong&gt;, these tools work exceptionally well.&lt;/p&gt;

&lt;p&gt;But once React applications scale into &lt;strong&gt;micro-frontend architectures&lt;/strong&gt;—with multiple teams, independent deployments, and runtime-loaded bundles—many familiar patterns start to break down.&lt;/p&gt;

&lt;p&gt;This post explores &lt;strong&gt;why React state management becomes difficult at scale&lt;/strong&gt; and introduces &lt;strong&gt;remote contexts&lt;/strong&gt;, an architectural approach for sharing state across distributed React applications.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Reality of Large-Scale React Applications
&lt;/h2&gt;

&lt;p&gt;Modern React systems often consist of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Multiple micro-frontends&lt;/li&gt;
&lt;li&gt;Independent build and deployment pipelines&lt;/li&gt;
&lt;li&gt;Runtime-loaded bundles (Module Federation, dynamic imports)&lt;/li&gt;
&lt;li&gt;Teams owning isolated business domains&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At this point, your frontend is no longer a single application—it’s a &lt;strong&gt;distributed system&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And distributed systems demand different architectural thinking.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why React Context and Hooks Struggle in Micro-Frontends
&lt;/h2&gt;

&lt;h3&gt;
  
  
  React Context Stops at Bundle Boundaries
&lt;/h3&gt;

&lt;p&gt;React Context only works within a single React tree.&lt;br&gt;&lt;br&gt;
When providers and consumers live in different bundles, context simply doesn’t cross that boundary.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prop Drilling Becomes Impossible
&lt;/h3&gt;

&lt;p&gt;When applications are compiled and deployed independently, passing props across boundaries is no longer viable.&lt;/p&gt;

&lt;h3&gt;
  
  
  Global State Becomes Too Global
&lt;/h3&gt;

&lt;p&gt;To compensate, teams often introduce:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large Redux stores&lt;/li&gt;
&lt;li&gt;Shared event buses&lt;/li&gt;
&lt;li&gt;Singleton services&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These approaches &lt;em&gt;work&lt;/em&gt;, but they introduce new problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tight coupling between teams&lt;/li&gt;
&lt;li&gt;Hard-to-debug state flows&lt;/li&gt;
&lt;li&gt;Performance bottlenecks&lt;/li&gt;
&lt;li&gt;Fear-driven deployments&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  The Real Problem Isn’t State—It’s Communication
&lt;/h2&gt;

&lt;p&gt;At scale, the challenge isn’t &lt;em&gt;how to store state&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It’s &lt;strong&gt;how applications communicate&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Most React state management tools assume:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The same team owns both the state and its consumers.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In micro-frontend architectures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ownership is distributed&lt;/li&gt;
&lt;li&gt;Consumers are unknown at build time&lt;/li&gt;
&lt;li&gt;Load order is unpredictable&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This requires a shift—from &lt;strong&gt;shared state&lt;/strong&gt; to &lt;strong&gt;shared contracts&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Are Remote Contexts?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;remote context&lt;/strong&gt; extends the idea of React Context beyond a single bundle.&lt;/p&gt;

&lt;p&gt;Key characteristics:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lives outside a single React tree&lt;/li&gt;
&lt;li&gt;Uses a publish/subscribe model&lt;/li&gt;
&lt;li&gt;Supports late subscribers&lt;/li&gt;
&lt;li&gt;Preserves the React hook-based developer experience&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To a React developer, it still &lt;em&gt;feels&lt;/em&gt; like &lt;code&gt;useContext&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Architecturally, it behaves like &lt;strong&gt;distributed state management&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Cross-Bundle Messaging in React Architectures
&lt;/h2&gt;

&lt;p&gt;Remote contexts rely on a lightweight messaging layer to communicate across micro-frontends.&lt;/p&gt;

&lt;p&gt;This layer can be implemented using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Module Federation shared modules&lt;/li&gt;
&lt;li&gt;&lt;code&gt;BroadcastChannel&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;postMessage&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Custom event transports&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The transport mechanism can change.&lt;br&gt;&lt;br&gt;
The architectural pattern stays the same.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Remote Contexts Work Well with React
&lt;/h2&gt;

&lt;p&gt;React already provides a solution for consuming external state safely:&lt;br&gt;&lt;br&gt;
&lt;code&gt;useSyncExternalStore&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Remote contexts use this API to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remain concurrent-safe&lt;/li&gt;
&lt;li&gt;Avoid tearing&lt;/li&gt;
&lt;li&gt;Ensure predictable re-renders&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React stays local.&lt;br&gt;&lt;br&gt;
State communication becomes distributed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example: Distributed React Dashboards
&lt;/h2&gt;

&lt;p&gt;Consider a dashboard where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One team owns authentication&lt;/li&gt;
&lt;li&gt;Another team owns analytics widgets&lt;/li&gt;
&lt;li&gt;A third team manages feature flags&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each micro-frontend:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Deploys independently&lt;/li&gt;
&lt;li&gt;Publishes updates to remote contexts&lt;/li&gt;
&lt;li&gt;Consumes only the data it needs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No shared Redux store.&lt;br&gt;&lt;br&gt;
No direct imports.&lt;br&gt;&lt;br&gt;
No hidden dependencies.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-World Challenges (and Why They’re Solvable)
&lt;/h2&gt;

&lt;p&gt;Distributed state introduces real concerns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Race conditions&lt;/strong&gt; → solved with snapshot replay&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type safety&lt;/strong&gt; → enforced through shared TypeScript contracts&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Versioning&lt;/strong&gt; → handled with schema evolution&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Debugging&lt;/strong&gt; → improved through observable context flow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These problems already exist in large systems.&lt;br&gt;&lt;br&gt;
Remote contexts make them &lt;strong&gt;explicit and manageable&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Migrating from Redux and Traditional State Management
&lt;/h2&gt;

&lt;p&gt;Remote contexts are not a replacement for local state or Redux.&lt;/p&gt;

&lt;p&gt;A practical migration strategy looks like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep local state local&lt;/li&gt;
&lt;li&gt;Expose only cross-application state as remote contexts&lt;/li&gt;
&lt;li&gt;Gradually reduce reliance on shared global stores&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This allows teams to adopt the pattern incrementally—without rewrites.&lt;/p&gt;




&lt;h2&gt;
  
  
  When Should You Use Remote Contexts?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Good fit when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You have multiple micro-frontends&lt;/li&gt;
&lt;li&gt;Teams deploy independently&lt;/li&gt;
&lt;li&gt;State must be shared across bundles&lt;/li&gt;
&lt;li&gt;Global stores cause performance or coordination issues&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Not needed when:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Building small or single-team applications&lt;/li&gt;
&lt;li&gt;Managing purely local UI state&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Architecture should match scale—not trends.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts: React Architecture Must Evolve with Scale
&lt;/h2&gt;

&lt;p&gt;React itself scales well.&lt;/p&gt;

&lt;p&gt;What doesn’t scale is applying &lt;strong&gt;single-app state management patterns to distributed frontend systems&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Remote contexts allow teams to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Move independently&lt;/li&gt;
&lt;li&gt;Share state intentionally&lt;/li&gt;
&lt;li&gt;Preserve the React developer experience&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As frontend systems grow, &lt;strong&gt;architecture—not libraries—becomes the differentiator&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Working code : &lt;a href="https://github.com/shanthipalani/monorepo-react-microfrontend/tree/remote-context-performant" rel="noopener noreferrer"&gt;https://github.com/shanthipalani/monorepo-react-microfrontend/tree/remote-context-performant&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>microfrontends</category>
      <category>architecture</category>
      <category>statemanagement</category>
    </item>
    <item>
      <title>structuredClone() — The Deep Copy Hero JavaScript Deserved 🦸‍♀️</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Wed, 31 Dec 2025 14:29:31 +0000</pubDate>
      <link>https://dev.to/shantih_palani/structuredclone-the-deep-copy-hero-javascript-deserved-2add</link>
      <guid>https://dev.to/shantih_palani/structuredclone-the-deep-copy-hero-javascript-deserved-2add</guid>
      <description>&lt;p&gt;Let’s be honest.&lt;br&gt;&lt;br&gt;
Every JavaScript developer has &lt;strong&gt;broken production at least once&lt;/strong&gt; because of &lt;em&gt;copying objects the wrong way&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;You thought you cloned it.&lt;br&gt;&lt;br&gt;
JavaScript smiled.&lt;br&gt;&lt;br&gt;
Then changed the original too.&lt;/p&gt;

&lt;p&gt;Enter &lt;strong&gt;&lt;code&gt;structuredClone()&lt;/code&gt;&lt;/strong&gt; — the native deep-cloning superhero that finally says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Relax. I got this.”&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  The Problem: “Why did my original object change?! 😭”
&lt;/h2&gt;

&lt;p&gt;Classic situation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shanthi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;skills&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;JavaScript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;React&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;skills&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;TypeScript&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;skills&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ["JavaScript", "React", "TypeScript"] 😱&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You didn’t mean to update the original…&lt;br&gt;&lt;br&gt;
JavaScript just assumed you were feeling adventurous.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Old (Painful) Way 😬
&lt;/h2&gt;

&lt;p&gt;We all tried this at some point:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It looks clever.&lt;br&gt;&lt;br&gt;
It feels clever.&lt;br&gt;&lt;br&gt;
But it betrays you silently.&lt;/p&gt;


&lt;h2&gt;
  
  
  What it breaks:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;❌ &lt;code&gt;Date&lt;/code&gt; becomes a string
&lt;/li&gt;
&lt;li&gt;❌ &lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt; vanish into thin air
&lt;/li&gt;
&lt;li&gt;❌ &lt;code&gt;undefined&lt;/code&gt;, &lt;code&gt;NaN&lt;/code&gt;, &lt;code&gt;Infinity&lt;/code&gt; disappear
&lt;/li&gt;
&lt;li&gt;❌ Circular references? App crash 💥
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically, it copies your data and &lt;strong&gt;forgets its personality&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Meet &lt;code&gt;structuredClone()&lt;/code&gt; 🧠✨
&lt;/h2&gt;

&lt;p&gt;JavaScript finally said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Okay fine, here’s a proper deep clone.”&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cloned&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it.&lt;br&gt;&lt;br&gt;
No imports.&lt;br&gt;&lt;br&gt;
No libraries.&lt;br&gt;&lt;br&gt;
No emotional damage.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Makes &lt;code&gt;structuredClone&lt;/code&gt; So Cool?
&lt;/h2&gt;

&lt;p&gt;✅ It actually understands JavaScript data.&lt;/p&gt;

&lt;h3&gt;
  
  
  It supports:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Objects &amp;amp; Arrays
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Date&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Map&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;RegExp&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BigInt&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;TypedArrays
&lt;/li&gt;
&lt;li&gt;Circular references (&lt;strong&gt;YES 🔥&lt;/strong&gt;)
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically, real-world data. Not just JSON-shaped dreams.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example: Deep Clone That Actually Works
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shanthi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;joined&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;clone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;clone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;joined&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setFullYear&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2030&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;joined&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getFullYear&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// Still 2024 😌&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No side effects.&lt;br&gt;&lt;br&gt;
No surprises.&lt;br&gt;&lt;br&gt;
No apology messages to your team.&lt;/p&gt;




&lt;h2&gt;
  
  
  Circular References? Bring It On 💪
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{};&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cloned&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cloned&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;cloned&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Old methods would:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Cry
&lt;/li&gt;
&lt;li&gt;❌ Throw errors
&lt;/li&gt;
&lt;li&gt;❌ Give up on life
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;structuredClone&lt;/code&gt; just nods politely and continues.&lt;/p&gt;




&lt;h2&gt;
  
  
  Map &amp;amp; Set — Finally Respected 🫶
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;map&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;([[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;a&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]]),&lt;/span&gt;
  &lt;span class="na"&gt;set&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;clone&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;clone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;b&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// false 🎉&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your original data remains &lt;strong&gt;unbothered&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What It Won’t Clone (And That’s Fair)
&lt;/h2&gt;

&lt;p&gt;Some things simply refuse to be cloned:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Functions (they have commitment issues)
&lt;/li&gt;
&lt;li&gt;❌ DOM nodes (use &lt;code&gt;cloneNode&lt;/code&gt;)
&lt;/li&gt;
&lt;li&gt;❌ Symbols
&lt;/li&gt;
&lt;li&gt;❌ &lt;code&gt;WeakMap&lt;/code&gt;, &lt;code&gt;WeakSet&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Try cloning these and JavaScript will politely throw a &lt;strong&gt;&lt;code&gt;DataCloneError&lt;/code&gt;&lt;/strong&gt; instead of silently ruining your data.&lt;br&gt;&lt;br&gt;
Honestly? We appreciate the honesty.&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;code&gt;structuredClone&lt;/code&gt; vs Spread Operator 🥊
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;original&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;shallow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;original&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;shallow&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// 2 ❌&lt;/span&gt;
&lt;span class="nx"&gt;deep&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;original&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// still 2 ✅&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Spread operator:&lt;/strong&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I’ll copy the top layer and hope for the best.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;structuredClone&lt;/code&gt;:&lt;/strong&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I’ll copy everything. Thoroughly.”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Performance: Should I Worry?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Faster than &lt;code&gt;JSON.parse(JSON.stringify())&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Optimized by modern JS engines
&lt;/li&gt;
&lt;li&gt;Safe for state cloning and message passing
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⚠️ Just don’t clone massive objects in tight loops unless you enjoy performance reviews.&lt;/p&gt;




&lt;h2&gt;
  
  
  Where You’ll Actually Use This
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;React state updates (immutability without headaches)
&lt;/li&gt;
&lt;li&gt;Redux / Zustand / any state manager
&lt;/li&gt;
&lt;li&gt;Web Workers
&lt;/li&gt;
&lt;li&gt;Undo / redo features
&lt;/li&gt;
&lt;li&gt;Caching snapshots
&lt;/li&gt;
&lt;li&gt;“Why did this mutate?” bug prevention
&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Browser &amp;amp; Runtime Support 🌍
&lt;/h2&gt;

&lt;p&gt;Good news:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Modern browsers ✅
&lt;/li&gt;
&lt;li&gt;Node.js 17+ ✅
&lt;/li&gt;
&lt;li&gt;Deno, Bun ✅
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No polyfills. No drama.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts 💭
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;structuredClone()&lt;/code&gt; is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Native
&lt;/li&gt;
&lt;li&gt;✅ Safe
&lt;/li&gt;
&lt;li&gt;✅ Deep
&lt;/li&gt;
&lt;li&gt;✅ Honest about errors
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re still using &lt;code&gt;JSON.parse(JSON.stringify())&lt;/code&gt;, it’s okay.&lt;br&gt;&lt;br&gt;
We all grow. 😄&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Modern JavaScript has given us a proper deep clone.&lt;br&gt;&lt;br&gt;
Let’s actually use it.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;💬 &lt;em&gt;Have you been betrayed by shallow copies before?&lt;br&gt;&lt;br&gt;
Share your cloning horror stories in the comments!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>node</category>
    </item>
    <item>
      <title>Shallow Copy vs Deep Copy in JavaScript — Quick and Clear explanation</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Tue, 09 Dec 2025 21:11:07 +0000</pubDate>
      <link>https://dev.to/shantih_palani/shallow-copy-vs-deep-copy-in-javascript-quick-clear-slightly-funny-4d98</link>
      <guid>https://dev.to/shantih_palani/shallow-copy-vs-deep-copy-in-javascript-quick-clear-slightly-funny-4d98</guid>
      <description>&lt;p&gt;Copying objects in JavaScript looks easy… until the original object changes when you didn’t touch it.&lt;br&gt;&lt;br&gt;
Congratulations — you’ve encountered &lt;em&gt;shallow copy chaos&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Let’s fix that in the simplest, funniest, most precise way possible.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧍‍♂️ What Is a Shallow Copy?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;shallow copy&lt;/strong&gt; only copies the top-level values.&lt;br&gt;&lt;br&gt;
Nested objects? Arrays?&lt;br&gt;&lt;br&gt;
JavaScript just hands you the same reference like a lazy coworker.&lt;/p&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shanthi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chennai&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;copy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Coimbatore&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="c1"&gt;// "Coimbatore" — betrayal detected 💔&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;Because only the top-level value (&lt;code&gt;name&lt;/code&gt;) was cloned.&lt;br&gt;&lt;br&gt;
The nested object (&lt;code&gt;address&lt;/code&gt;) was &lt;strong&gt;shared&lt;/strong&gt;, so modifying it changes the original.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 What Is a Deep Copy?
&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;deep copy&lt;/strong&gt; clones &lt;em&gt;every level&lt;/em&gt; of the object.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No shared references
&lt;/li&gt;
&lt;li&gt;No accidental mutations
&lt;/li&gt;
&lt;li&gt;No “WHY DID THIS CHANGE??” debugging nightmares
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Example
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Shanthi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;city&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Chennai&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;structuredClone&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;deep&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Coimbatore&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;city&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// "Chennai" — original untouched ✨&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🛠 Copying Methods
&lt;/h2&gt;

&lt;h3&gt;
  
  
  🔹 Shallow Copy Methods
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;{ ...obj }&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Object.assign({}, obj)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;array.slice()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Array.from()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⚠️ &lt;strong&gt;Note:&lt;/strong&gt; All shallow copy methods copy nested objects &lt;strong&gt;by reference&lt;/strong&gt;, not by value.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 Deep Copy Methods
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;structuredClone(obj)&lt;/code&gt; ← &lt;strong&gt;Best + modern&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Custom recursive deep clone&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;JSON.parse(JSON.stringify(obj))&lt;/code&gt;
⚠️ &lt;strong&gt;Breaks for:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Date&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;&lt;code&gt;undefined&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;RegExp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Circular references&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 When Should You Use Which?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✔️ Use &lt;strong&gt;Shallow Copy&lt;/strong&gt; when:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Only top-level values change
&lt;/li&gt;
&lt;li&gt;The object is simple
&lt;/li&gt;
&lt;li&gt;You just need a quick non-nested clone&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ✔️ Use &lt;strong&gt;Deep Copy&lt;/strong&gt; when:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Your data is nested
&lt;/li&gt;
&lt;li&gt;You need immutability (React, Redux, etc.)
&lt;/li&gt;
&lt;li&gt;You want predictable, safe updates&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🧘 TL;DR Table
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Shallow Copy&lt;/th&gt;
&lt;th&gt;Deep Copy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Copies nested values&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Safe for complex data&lt;/td&gt;
&lt;td&gt;❌&lt;/td&gt;
&lt;td&gt;✅&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Surprise bugs&lt;/td&gt;
&lt;td&gt;High&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best method&lt;/td&gt;
&lt;td&gt;Spread / &lt;code&gt;Object.assign&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;&lt;code&gt;structuredClone()&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  🏁 Summary
&lt;/h2&gt;

&lt;p&gt;Shallow and deep copying may sound similar, but they behave completely differently in JavaScript.&lt;br&gt;&lt;br&gt;
A &lt;strong&gt;shallow copy&lt;/strong&gt; only duplicates the first level, leaving nested objects &lt;em&gt;linked&lt;/em&gt; and ready to cause sneaky bugs.&lt;br&gt;&lt;br&gt;
A &lt;strong&gt;deep copy&lt;/strong&gt;, however, clones every level, giving you safe, predictable, mutation-free data — especially important in React, Redux, and any place where immutability matters.&lt;/p&gt;

&lt;p&gt;When in doubt:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;strong&gt;shallow copy&lt;/strong&gt; for simple, flat objects.
&lt;/li&gt;
&lt;li&gt;Use &lt;strong&gt;deep copy&lt;/strong&gt; for anything nested or important.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your future debugging sessions will thank you. 🚀&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>web</category>
      <category>react</category>
    </item>
    <item>
      <title>🚀 Client-Side vs Server-Side CORS: Understanding the Real Difference</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Thu, 04 Dec 2025 20:49:34 +0000</pubDate>
      <link>https://dev.to/shantih_palani/client-side-vs-server-side-cors-understanding-the-real-difference-52l9</link>
      <guid>https://dev.to/shantih_palani/client-side-vs-server-side-cors-understanding-the-real-difference-52l9</guid>
      <description>&lt;p&gt;If you’ve ever screamed at your monitor because of a &lt;em&gt;mysterious&lt;/em&gt; CORS error…&lt;br&gt;&lt;br&gt;
Congratulations — you are officially a web developer. 🎉&lt;/p&gt;

&lt;p&gt;CORS is like that strict bouncer outside the club who won’t let you in even though you &lt;em&gt;swear&lt;/em&gt; you're on the list.&lt;/p&gt;

&lt;p&gt;This blog will finally explain the difference between &lt;strong&gt;Client-Side CORS and Server-Side CORS&lt;/strong&gt;, without making your brain melt like a broken build.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧐 What Is CORS, Really?
&lt;/h2&gt;

&lt;p&gt;CORS stands for &lt;strong&gt;Cross-Origin Resource Sharing&lt;/strong&gt; — which sounds fancy, but really means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey browser, can this website talk to that other website? Or is it a stranger danger situation?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The browser is extremely paranoid.&lt;br&gt;&lt;br&gt;
If &lt;strong&gt;domain A&lt;/strong&gt; calls &lt;strong&gt;domain B&lt;/strong&gt;, the browser goes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hold up. Who sent you? Show me your passport, Aadhar card, PAN card, and two 2x2 photos.”&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  🤓 Client-Side vs Server-Side CORS: The Plot Twist
&lt;/h2&gt;

&lt;p&gt;People keep saying &lt;em&gt;“client-side CORS”&lt;/em&gt; and &lt;em&gt;“server-side CORS,”&lt;/em&gt; but here’s the truth:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Only the server decides CORS. The client is just a confused teenager asking for permission.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Still, both sides play a role — so let’s decode them.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔵 Client-Side CORS (AKA: The Illusion of Control)
&lt;/h2&gt;

&lt;p&gt;Developers be like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/api&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cors&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And expect the browser to go:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Yes sir! CORS enabled! You’re a genius!”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But no.&lt;br&gt;&lt;br&gt;
The browser basically says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Cute. But I enforce the rules. Sit down.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Client-side "CORS" is really about &lt;strong&gt;&lt;em&gt;how you send the request&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;mode: "cors"&lt;/code&gt; → “Please let me in!”
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mode: "no-cors"&lt;/code&gt; → “Fine, I’ll leave. I didn’t want to see the response anyway.”
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;credentials: "include"&lt;/code&gt; → “Here are my cookies, please don’t judge.”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⚠️ &lt;strong&gt;But the client CANNOT actually enable CORS.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s like trying to unlock a door by telling the door politely.&lt;br&gt;&lt;br&gt;
The server still holds the key.&lt;/p&gt;


&lt;h2&gt;
  
  
  🟣 Server-Side CORS (The Real Boss Here)
&lt;/h2&gt;

&lt;p&gt;This is where the &lt;em&gt;actual magic&lt;/em&gt; happens.&lt;/p&gt;

&lt;p&gt;If the server doesn’t approve your origin…&lt;br&gt;&lt;br&gt;
The browser will block you faster than a bad ex.&lt;/p&gt;

&lt;p&gt;Servers respond with headers like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Access-Control-Allow-Origin: https://myapp.com
Access-Control-Allow-Methods: GET, POST, DELETE
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Credentials: true
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only then does the browser say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Okay, fine. I guess you're allowed in.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Example (Express.js)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://myapp.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Example (Next.js API Route)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Access-Control-Allow-Origin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://myapp.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Access-Control-Allow-Credentials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;true&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you forget even &lt;em&gt;one&lt;/em&gt; header?&lt;/p&gt;

&lt;p&gt;Boom.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;CORS error.&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Your day is ruined. Your coffee goes cold. Your teammates hear a scream.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Simple vs Preflight Requests (AKA: Browser Drama)
&lt;/h2&gt;

&lt;p&gt;The browser sends:&lt;/p&gt;

&lt;h3&gt;
  
  
  👉 Simple requests
&lt;/h3&gt;

&lt;p&gt;These are chill. The browser is like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“GET or POST with simple headers? Fine, go ahead.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  👉 Preflight requests
&lt;/h3&gt;

&lt;p&gt;These are drama.&lt;/p&gt;

&lt;p&gt;If you use:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;PUT&lt;/code&gt;, &lt;code&gt;PATCH&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Custom headers
&lt;/li&gt;
&lt;li&gt;JSON body
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The browser becomes your mom:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Wait. Before you go, WHERE are you going? Who’s going with you? When will you come back???”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It sends an &lt;strong&gt;OPTIONS&lt;/strong&gt; request first.&lt;br&gt;&lt;br&gt;
If the server doesn’t respond correctly?&lt;br&gt;&lt;br&gt;
Blocked. Again.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Summary Table for Geniuses Who Scrolled Too Fast
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Thing&lt;/th&gt;
&lt;th&gt;Client Side&lt;/th&gt;
&lt;th&gt;Server Side&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Who’s in control?&lt;/td&gt;
&lt;td&gt;Lol. Not you.&lt;/td&gt;
&lt;td&gt;The real boss.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Can it allow a request?&lt;/td&gt;
&lt;td&gt;❌ Nope&lt;/td&gt;
&lt;td&gt;✅ Absolutely&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Can it trigger preflight?&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;⚠️ Must respond properly&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Is it real CORS?&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;td&gt;✅ Yes, 100% legit&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;CORS errors might feel like a personal attack from the universe, but the rule is simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Client requests. Server approves. Browser judges.&lt;br&gt;&lt;br&gt;
Just like real life.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If everyone plays their part correctly, CORS becomes easy.&lt;br&gt;&lt;br&gt;
If not… well, enjoy the next 3 hours of debugging. 😅&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>cors</category>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>React.memo vs useMemo</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Sun, 23 Nov 2025 14:33:38 +0000</pubDate>
      <link>https://dev.to/shantih_palani/reactmemo-vs-usememo-3h3k</link>
      <guid>https://dev.to/shantih_palani/reactmemo-vs-usememo-3h3k</guid>
      <description>&lt;h1&gt;
  
  
  React.memo vs useMemo — Explained
&lt;/h1&gt;

&lt;p&gt;If you've ever stared at your React component tree wondering &lt;em&gt;"Why are you re-rendering? I didn’t even touch you!"&lt;/em&gt; — congratulations, you're officially a React developer.&lt;/p&gt;

&lt;p&gt;With React 19 rolling into town like a cool new intern, many devs still ask: &lt;strong&gt;“Do React.memo and useMemo still matter?”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Short answer: &lt;strong&gt;YES.&lt;/strong&gt; Long answer: You’re about to read it.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 The Real Difference
&lt;/h2&gt;

&lt;p&gt;Let’s clear the confusion once and for all:&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;🔹 React.memo — The Component Bodyguard&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;React.memo wraps a &lt;strong&gt;component&lt;/strong&gt;, preventing it from re-rendering unless its props change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Think of React.memo as&lt;/strong&gt;:&lt;br&gt;
A bouncer at the club door checking props IDs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Greeting&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rendered!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;name&lt;/code&gt; doesn’t change → &lt;strong&gt;No re-render.&lt;/strong&gt;&lt;br&gt;
If &lt;code&gt;name&lt;/code&gt; changes → &lt;strong&gt;VIP access.&lt;/strong&gt;&lt;/p&gt;


&lt;h3&gt;
  
  
  &lt;strong&gt;🔹 useMemo — The Expensive Calculator&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;useMemo memoizes a &lt;strong&gt;value&lt;/strong&gt;, usually something expensive to compute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Think of useMemo as&lt;/strong&gt;:&lt;br&gt;
A lazy accountant who refuses to redo work unless absolutely necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useMemo&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;expensiveCalculation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;items&lt;/code&gt; doesn’t change → useMemo says: &lt;em&gt;"Bro, I already did this."&lt;/em&gt;&lt;br&gt;
If it does → reluctantly recomputes.&lt;/p&gt;




&lt;h2&gt;
  
  
  🥊 React.memo vs useMemo — Head-to-Head
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;React.memo&lt;/th&gt;
&lt;th&gt;useMemo&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Purpose&lt;/td&gt;
&lt;td&gt;Prevent component re-render&lt;/td&gt;
&lt;td&gt;Cache expensive calculations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Works on&lt;/td&gt;
&lt;td&gt;Components&lt;/td&gt;
&lt;td&gt;Values (numbers, objects, arrays, results)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Checks dependencies&lt;/td&gt;
&lt;td&gt;Props&lt;/td&gt;
&lt;td&gt;Dependency array&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Best for&lt;/td&gt;
&lt;td&gt;Heavy UI components&lt;/td&gt;
&lt;td&gt;Heavy computations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Worst use case&lt;/td&gt;
&lt;td&gt;Wrapping everything blindly&lt;/td&gt;
&lt;td&gt;Memoizing cheap functions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  🧩 When to Use What?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ✔ Use &lt;strong&gt;React.memo&lt;/strong&gt; if:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Component is heavy to re-render.&lt;/li&gt;
&lt;li&gt;Renders the same UI if props don’t change.&lt;/li&gt;
&lt;li&gt;Parent re-renders too often.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Don't use&lt;/strong&gt; React.memo if the props are always changing anyway (it does nothing then).&lt;/p&gt;

&lt;h3&gt;
  
  
  ✔ Use &lt;strong&gt;useMemo&lt;/strong&gt; if:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You’re running expensive logic inside render.&lt;/li&gt;
&lt;li&gt;You pass stable memoized values to child components.&lt;/li&gt;
&lt;li&gt;You want to avoid useless recalculations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Don't use&lt;/strong&gt; useMemo for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Cheap calculations.&lt;/li&gt;
&lt;li&gt;Every single variable (&lt;em&gt;this is not TypeScript, calm down&lt;/em&gt;).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎨 Diagram Time!
&lt;/h2&gt;

&lt;h3&gt;
  
  
  "What they actually do"
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React.memo                     useMemo
--------------                --------------
Component? Stop here.         Value? Store here.
Props same? Skip render.      Dependencies same? Skip computing.
Props changed? Render!        Changed? Recompute!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If React.memo were a person → &lt;strong&gt;security guard&lt;/strong&gt;&lt;br&gt;
If useMemo were a person → &lt;strong&gt;lazy mathematician&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🧪 Real-Life Example (The Comedy Version)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// useMemo: "Don't make me calculate again!"&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useMemo&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Computing total...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ExpensiveUI&lt;/span&gt; &lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// React.memo: "You're not getting in unless your props change!"&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ExpensiveUI&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ExpensiveUI&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;total&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rendering ExpensiveUI&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Total: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;total&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this drama:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;useMemo&lt;/strong&gt; prevents recalculations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React.memo&lt;/strong&gt; prevents component re-renders.&lt;/li&gt;
&lt;li&gt;Your CPU lives to fight another day.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🚀 So… Are They Still Useful in React 19?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;YES.&lt;/strong&gt;&lt;br&gt;
Even with improved React internals, concurrent features, and better scheduling —&lt;br&gt;
&lt;code&gt;React.memo&lt;/code&gt; and &lt;code&gt;useMemo&lt;/code&gt; remain &lt;strong&gt;performance best friends&lt;/strong&gt;, especially in large apps.&lt;/p&gt;

&lt;p&gt;React 19 doesn’t remove them.&lt;br&gt;
It doesn’t deprecate them.&lt;br&gt;
It doesn’t roast them on stage.&lt;/p&gt;

&lt;p&gt;They're still very much alive and helpful — when used wisely.&lt;/p&gt;




&lt;h2&gt;
  
  
  😂 The Funniest Explanation
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;React.memo:&lt;/strong&gt; “Bro, don’t re-render unless something ACTUALLY changed.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useMemo:&lt;/strong&gt; “Bro, stop calculating that again. I saved the answer already.”&lt;/p&gt;




&lt;h2&gt;
  
  
  🧁 Final Thoughts (Sweet &amp;amp; Short)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;React.memo&lt;/strong&gt; = Avoid useless re-renders.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;useMemo&lt;/strong&gt; = Avoid useless re-calculations.&lt;/li&gt;
&lt;li&gt;Don’t overuse them.&lt;/li&gt;
&lt;li&gt;Don’t underuse them.
Use them like salt: Just enough, or everything becomes weird.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>react</category>
      <category>reactmemo</category>
      <category>react19</category>
    </item>
    <item>
      <title>Is React.memo Still Useful in React 19? A Practical Guide for 2025</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Sun, 23 Nov 2025 14:18:06 +0000</pubDate>
      <link>https://dev.to/shantih_palani/is-reactmemo-still-useful-in-react-19-a-practical-guide-for-2025-4lj5</link>
      <guid>https://dev.to/shantih_palani/is-reactmemo-still-useful-in-react-19-a-practical-guide-for-2025-4lj5</guid>
      <description>&lt;p&gt;React 19 introduced several internal improvements, async rendering refinements, and smarter rendering heuristics. Because of this, many developers began asking a familiar question again:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“Do we still need React.memo in React 19?”&lt;br&gt;
Short answer: Yes — but use it deliberately.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s break this down in a simple, practical way.&lt;/p&gt;
&lt;h2&gt;
  
  
  ⭐ &lt;strong&gt;What React.memo Does (Quick Refresher)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;React.memo is a higher-order component that prevents unnecessary re-renders when the component’s props haven’t changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserCard = React.memo(function UserCard({ user }) {
  return &amp;lt;div&amp;gt;{user.name}&amp;lt;/div&amp;gt;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When used correctly, this can reduce wasted renders and improve performance in large lists, dashboards, or heavy UI sections.&lt;/p&gt;




&lt;h2&gt;
  
  
  ⚡ &lt;strong&gt;What Changed in React 19?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;React 19 brought several rendering optimizations:&lt;/p&gt;

&lt;p&gt;✔ &lt;strong&gt;Smarter scheduling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React handles background rendering better and avoids blocking work.&lt;/p&gt;

&lt;p&gt;✔ &lt;strong&gt;More efficient reconciliation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some internal improvements reduce excessive re-renders that used to happen in older versions.&lt;/p&gt;

&lt;p&gt;✔ &lt;strong&gt;Fewer unnecessary re-renders by default&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React is better at skipping updates when values obviously haven't changed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;BUT:&lt;/strong&gt;&lt;br&gt;
React still &lt;strong&gt;does not&lt;/strong&gt; do deep prop comparisons.&lt;/p&gt;

&lt;p&gt;React still &lt;strong&gt;cannot know if a child component is expensive&lt;/strong&gt; to render.&lt;/p&gt;

&lt;p&gt;React still &lt;strong&gt;re-renders on parent render&lt;/strong&gt; unless you prevent it.&lt;/p&gt;

&lt;p&gt;Meaning: &lt;strong&gt;The fundamental reason for using &lt;code&gt;React.memo&lt;/code&gt; still exists&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎯 So… Is &lt;code&gt;React.memo&lt;/code&gt; Still Recommended in 2025?&lt;/strong&gt;&lt;br&gt;
Absolutely YES — but with intention.&lt;/p&gt;


&lt;h2&gt;
  
  
  ✔ &lt;strong&gt;When You SHOULD Use &lt;code&gt;React.memo&lt;/code&gt;&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Use it when:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1️⃣ Components receive stable props&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large list items (UserRow, ProductCard)&lt;/li&gt;
&lt;li&gt;Table rows&lt;/li&gt;
&lt;li&gt;Reusable UI blocks with minimal prop changes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2️⃣ The component is expensive&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Heavy computation&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large DOM&lt;/li&gt;
&lt;li&gt;Complex markup&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3️⃣ The component appears in a list&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React lists are the biggest beneficiaries of &lt;code&gt;React.memo&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4️⃣ Parent component re-renders frequently&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the parent updates often, memoizing the child prevents ripple renders.&lt;/p&gt;


&lt;h2&gt;
  
  
  ❌ When NOT to Use &lt;code&gt;React.memo&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Skip it when:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1️⃣ Component is cheap and simple&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Small button components, labels, icons, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2️⃣ Props change almost every render&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If the component always needs to render, memo brings no benefit.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3️⃣ You’re passing non-memoized objects every time&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;Component data={{ a: 1 }} /&amp;gt;  // new object each render → memo useless&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You'll need useMemo or stable references for React.memo to work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4️⃣ Premature optimization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Don’t wrap every component by default — it adds a comparison cost.&lt;/p&gt;


&lt;h2&gt;
  
  
  📌 What About Server Components (RSC)?
&lt;/h2&gt;

&lt;p&gt;Many developers wondered if &lt;code&gt;React.memo&lt;/code&gt; becomes irrelevant because of server-driven rendering.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;No *&lt;/em&gt;— because &lt;code&gt;React.memo&lt;/code&gt; is for client components.&lt;/p&gt;

&lt;p&gt;React Server Components don’t re-render in the browser.&lt;br&gt;
Client Components do, and that’s where &lt;code&gt;React.memo&lt;/code&gt; still matters.&lt;/p&gt;


&lt;h2&gt;
  
  
  ✔ Real-World Example (React 19)
&lt;/h2&gt;

&lt;p&gt;Without memo:&lt;/p&gt;

&lt;p&gt;Every time the parent renders, all items re-render.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
function UserList({ users }) {
  return users.map(u =&amp;gt; &amp;lt;UserItem key={u.id} user={u} /&amp;gt;);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With memo:&lt;/p&gt;

&lt;p&gt;Each item re-renders only when its own props change.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const UserItem = React.memo(function UserItem({ user }) {
  return &amp;lt;div&amp;gt;{user.name}&amp;lt;/div&amp;gt;;
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In large lists:&lt;br&gt;
&lt;strong&gt;Before React 19 → critical&lt;br&gt;
After React 19 → still critical&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Final Verdict
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;React.memo&lt;/code&gt; is STILL useful in React 19 — very much so.&lt;/p&gt;

&lt;p&gt;React’s new optimizations don't eliminate the need to prevent unnecessary re-renders. They simply make React faster by default. But:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React doesn’t magically skip renders.&lt;/li&gt;
&lt;li&gt;React doesn’t compare deep props.&lt;/li&gt;
&lt;li&gt;React doesn’t know your component’s render cost.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So you still need &lt;code&gt;React.memo&lt;/code&gt; when you want to explicitly optimize.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;📝 Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React 19 improves rendering, but it doesn’t replace what &lt;code&gt;React.memo&lt;/code&gt; offers. &lt;code&gt;React.memo&lt;/code&gt; remains a powerful performance optimization tool — especially for lists, expensive components, and frequently re-rendered UIs. Use it intentionally, not everywhere, and it will continue to provide real performance wins in modern React applications.&lt;/p&gt;




&lt;p&gt;Read about &lt;strong&gt;React.memo vs useMemo&lt;/strong&gt; in this &lt;a href="https://dev.to/shantih_palani/reactmemo-vs-usememo-3h3k"&gt;blog &lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>performance</category>
      <category>react</category>
    </item>
    <item>
      <title>🛠️ Migrating from JavaScript to TypeScript: Strategies and Gotchas</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Thu, 31 Jul 2025 06:42:45 +0000</pubDate>
      <link>https://dev.to/shantih_palani/migrating-from-javascript-to-typescript-strategies-and-gotchas-4e68</link>
      <guid>https://dev.to/shantih_palani/migrating-from-javascript-to-typescript-strategies-and-gotchas-4e68</guid>
      <description>&lt;p&gt;If you're thinking about migrating your JavaScript codebase to TypeScript, you're not alone — and you're definitely on the right track. TypeScript offers type safety, better tooling, and a more confident developer experience. But a migration isn't just a simple "rename-all-the-files" process. It's a journey — and like any journey, it’s smoother with a map. 🗺️&lt;/p&gt;

&lt;p&gt;In this post, I'll walk you through a practical migration strategy and highlight some common gotchas to avoid.&lt;/p&gt;

&lt;p&gt;✅ Why Migrate to TypeScript?&lt;/p&gt;

&lt;p&gt;🔍 Catch errors before they happen (at compile time)&lt;/p&gt;

&lt;p&gt;✨ Enjoy better IntelliSense and code navigation&lt;/p&gt;

&lt;p&gt;🛡️ Refactor with confidence&lt;/p&gt;

&lt;p&gt;📚 Your types are your documentation&lt;/p&gt;

&lt;p&gt;Let’s make your codebase future-proof.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔄 Migration Strategies
&lt;/h2&gt;

&lt;h2&gt;
  
  
  1. Start with the TypeScript Compiler
&lt;/h2&gt;

&lt;p&gt;Install TypeScript and initialize the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev typescript
npx tsc --init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a &lt;code&gt;tsconfig.json&lt;/code&gt; file — the heart of your TS setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Enable JavaScript Compatibility
&lt;/h2&gt;

&lt;p&gt;You can type-check your existing &lt;code&gt;.js&lt;/code&gt; files without converting them yet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// tsconfig.json
{
  "compilerOptions": {
    "allowJs": true,
    "checkJs": true,
    "outDir": "dist"
  },
  "include": ["src"]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Rename Files Gradually
&lt;/h2&gt;

&lt;p&gt;Start renaming &lt;code&gt;.js&lt;/code&gt; → &lt;code&gt;.ts&lt;/code&gt; (or &lt;code&gt;.jsx&lt;/code&gt; → &lt;code&gt;.tsx&lt;/code&gt;) one file at a time.&lt;/p&gt;

&lt;p&gt;Start with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Utility functions&lt;/li&gt;
&lt;li&gt;Isolated modules&lt;/li&gt;
&lt;li&gt;Non-UI logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avoid renaming everything at once — it’s easier to debug issues incrementally.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Add Type Annotations Where Needed
&lt;/h2&gt;

&lt;p&gt;Start small. Focus on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Function arguments and return types&lt;/li&gt;
&lt;li&gt;Object shapes using interfaces or type aliases&lt;/li&gt;
&lt;li&gt;Constants and enums
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type User = { name: string };

function greet(user: User): string {
  return `Hello, ${user.name}`;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Leverage JSDoc in &lt;code&gt;.js&lt;/code&gt; Files
&lt;/h2&gt;

&lt;p&gt;Want TS support without converting a file yet? Add JSDoc:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 * @param {string} name
 * @returns {string}
 */
function greet(name) {
  return `Hello, ${name}`;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a great way to introduce typing without renaming.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Use &lt;code&gt;any&lt;/code&gt; and &lt;code&gt;@ts-ignore&lt;/code&gt; Sparingly
&lt;/h2&gt;

&lt;p&gt;Yes, they can unblock you. But track them down and clean them up later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// @ts-ignore
someLegacyCode();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Tighten the Compiler Gradually
&lt;/h2&gt;

&lt;p&gt;Once you're confident, turn on stricter settings in &lt;code&gt;tsconfig.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"strict": true,
"noImplicitAny": true,
"strictNullChecks": true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enable them one at a time to avoid overwhelming yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  ⚠️ Gotchas to Watch For
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;🧩 Dynamic Code Is Hard to Type&lt;/strong&gt;&lt;br&gt;
Things like &lt;code&gt;eval&lt;/code&gt;, &lt;code&gt;Object.assign&lt;/code&gt;, or deeply dynamic object keys are hard to infer. Consider refactoring those.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📦 Missing Types for Libraries&lt;/strong&gt;&lt;br&gt;
Use DefinitelyTyped when needed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev @types/lodash

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If no types exist, you can write your own &lt;code&gt;*.d.ts&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔀 Implicit &lt;code&gt;any&lt;/code&gt; Types&lt;/strong&gt;&lt;br&gt;
You’ll hit this a lot if noImplicitAny is enabled:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function log(message) {
  console.log(message);
}
//       ~~~~~~~~ Error: Implicit any

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;⚛️ JSX Requires &lt;code&gt;.tsx&lt;/code&gt;&lt;/strong&gt;&lt;br&gt;
Using React? Any file that includes JSX must use the &lt;code&gt;.tsx&lt;/code&gt; extension.&lt;/p&gt;

&lt;p&gt;Also, don’t forget to type your props:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type ButtonProps = {
  label: string;
};

function Button({ label }: ButtonProps) {
  return &amp;lt;button&amp;gt;{label}&amp;lt;/button&amp;gt;;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🧪 Update Your Build + Test Tools&lt;/strong&gt;&lt;br&gt;
Make sure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Webpack or Vite is configured to handle &lt;code&gt;.ts&lt;/code&gt; files&lt;/li&gt;
&lt;li&gt;Babel has &lt;code&gt;@babel/preset-typescript&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Jest uses &lt;code&gt;ts-jest&lt;/code&gt; or &lt;code&gt;babel-jest&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🧭 Your Migration Roadmap&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Phase&lt;/th&gt;
&lt;th&gt;What to Do&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;🧪 Enable Type Checking&lt;/td&gt;
&lt;td&gt;Use &lt;code&gt;allowJs&lt;/code&gt; + &lt;code&gt;checkJs&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🔀 Rename Incrementally&lt;/td&gt;
&lt;td&gt;Convert &lt;code&gt;.js&lt;/code&gt; → &lt;code&gt;.ts&lt;/code&gt; in small batches&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;✍️ Add Types Slowly&lt;/td&gt;
&lt;td&gt;Start with functions, constants, object shapes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;⚙️ Configure Tools&lt;/td&gt;
&lt;td&gt;Update build/test tooling&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;🧼 Clean Up&lt;/td&gt;
&lt;td&gt;Remove &lt;code&gt;any&lt;/code&gt;, &lt;code&gt;@ts-ignore&lt;/code&gt;, etc.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;✨ Final Thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Migrating to TypeScript doesn’t have to be overwhelming. It’s not an all-or-nothing decision. Use a gradual, iterative approach — and before you know it, you'll have a fully typed, safer, and more enjoyable codebase.&lt;/p&gt;

&lt;p&gt;Your future self (and your team) will thank you. 🙌&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thanks for reading! Have you tried migrating a JS project to TypeScript? Share your story or tips in the comments below.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>ts</category>
      <category>migration</category>
    </item>
    <item>
      <title>Exploring the Exciting New Features in React 18</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Tue, 04 Jun 2024 12:54:18 +0000</pubDate>
      <link>https://dev.to/shantih_palani/exploring-the-exciting-new-features-in-react-18-54m4</link>
      <guid>https://dev.to/shantih_palani/exploring-the-exciting-new-features-in-react-18-54m4</guid>
      <description>&lt;p&gt;React 18 is a significant update for one of the most popular JavaScript libraries used for building user interfaces. This version introduces several exciting new features and improvements that aim to enhance performance, improve the developer experience, and enable new use cases. In this post, we’ll explore some of the standout features of React 18 and what they mean for developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Concurrent Rendering&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;One of the most anticipated features in React 18 is &lt;strong&gt;Concurrent Rendering&lt;/strong&gt;. This new rendering mechanism allows React to prepare multiple versions of the UI at the same time. This can improve the user experience by making the UI more responsive and fluid, especially in applications with complex, interactive interfaces.&lt;/p&gt;

&lt;p&gt;Concurrent Rendering enables React to interrupt and pause work, then continue later. This means your app can stay responsive even during heavy rendering tasks. For example, if a user interaction is more urgent, React can prioritize rendering that over less critical tasks.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useTransition&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isPending&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useTransition&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setInput&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setList&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleChange&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setInput&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newList&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5000&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nf"&gt;setList&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newList&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isPending&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Loading...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Automatic Batching
&lt;/h2&gt;

&lt;p&gt;React 18 introduces Automatic Batching, which optimizes the way updates are processed. Previously, React batched state updates that occurred within event handlers. However, updates that happened outside of event handlers, like those in setTimeouts or native event listeners, weren’t batched.&lt;/p&gt;

&lt;p&gt;With React 18, all updates are automatically batched, regardless of where they originate. This leads to fewer renders and better performance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Before React 18&lt;/span&gt;
&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;setFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flag&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Two separate renders&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// With React 18&lt;/span&gt;
&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;setFlag&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;flag&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="c1"&gt;// Only one render&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  New Suspense Features
&lt;/h2&gt;

&lt;p&gt;React’s Suspense feature, which was introduced earlier, has received significant updates in React 18. Suspense allows components to “wait” for something before they render. This is particularly useful for handling asynchronous data fetching.&lt;/p&gt;

&lt;p&gt;In React 18, Suspense works seamlessly with Concurrent Rendering to make data fetching more efficient and the UI more resilient. For example, you can now use Suspense to control loading states more granularly, ensuring that your application remains responsive and visually consistent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./MyComponent&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Transitions
&lt;/h2&gt;

&lt;p&gt;Transitions in React 18 allow developers to distinguish between urgent and non-urgent updates. This is particularly useful for distinguishing between interactions that need immediate feedback (like typing in a text box) and those that can be deferred (like loading a new page).&lt;/p&gt;

&lt;p&gt;The new &lt;strong&gt;useTransition&lt;/strong&gt; hook lets you mark updates as transitions, allowing React to keep the UI responsive during non-urgent updates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useTransition&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isPending&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useTransition&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nf"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;startTransition API&lt;/strong&gt;&lt;br&gt;
The startTransition API complements the useTransition hook by allowing developers to mark updates as transitions. This helps React prioritize urgent updates over non-urgent ones, ensuring a smooth user experience.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startTransition&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Increment&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Improved Server-Side Rendering
&lt;/h2&gt;

&lt;p&gt;React 18 brings significant improvements to Server-Side Rendering (SSR) with the introduction of a new API called react-dom/server. This API allows for more efficient streaming of HTML, which can improve the performance of server-rendered React applications.&lt;/p&gt;

&lt;p&gt;The new streaming SSR architecture lets the server send content to the client as soon as it’s ready, rather than waiting for the entire component tree to be rendered. This can lead to faster load times and a better user experience.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;renderToPipeableStream&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react-dom/server&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;express&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;express&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;express&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;req&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;renderToPipeableStream&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;onShellReady&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHeader&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;text/html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;stream&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;listen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Server is running on port 3000&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Server Components
&lt;/h2&gt;

&lt;p&gt;Another major addition to React 18 is Server Components. Server Components enable developers to build apps that leverage both the server and the client for rendering, resulting in faster load times and reduced bundle sizes.&lt;/p&gt;

&lt;p&gt;Server Components allow parts of the UI to be rendered on the server and sent to the client as HTML. This can significantly reduce the amount of JavaScript that needs to be loaded and executed on the client, leading to faster initial renders and improved performance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// MyComponent.server.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyComponent&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;server&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// App.client.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./MyComponent.server&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;br&gt;
javascript&lt;br&gt;
&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
React 18 is packed with features that enhance performance, improve the developer experience, and open up new possibilities for building modern web applications. Concurrent Rendering, Automatic Batching, enhanced Suspense, Transitions, improved SSR, and Server Components are just a few of the exciting additions.&lt;/p&gt;

&lt;p&gt;As developers, these new tools and improvements allow us to build more responsive, efficient, and user-friendly applications. With React 18, the future of web development looks brighter than ever.&lt;/p&gt;

&lt;p&gt;Stay tuned to &lt;strong&gt;Shanthi's Dev Diary&lt;/strong&gt; series for more in-depth tutorials and insights into the latest in web development!&lt;/p&gt;

</description>
      <category>react</category>
      <category>react18</category>
      <category>reactjsdevelopment</category>
    </item>
    <item>
      <title>Frontend Challenge June Edition - Take me to the beach</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Thu, 30 May 2024 20:43:44 +0000</pubDate>
      <link>https://dev.to/shantih_palani/frontend-challenge-june-edition-take-me-to-the-beach-2h6h</link>
      <guid>https://dev.to/shantih_palani/frontend-challenge-june-edition-take-me-to-the-beach-2h6h</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for [Frontend Challenge v24.04.17]((&lt;a href="https://dev.to/challenges/frontend-2024-05-29"&gt;https://dev.to/challenges/frontend-2024-05-29&lt;/a&gt;), Glam Up My Markup: Beaches&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;Take me to the beach!&lt;/p&gt;

&lt;p&gt;Welcome to our collection of the world's top beaches. Experience it all with two breathtaking views: the tranquil night scene and the vibrant morning ambiance. Plus, immerse yourself further with a gallery of stunning beach snapshots.&lt;/p&gt;

&lt;p&gt;The application isbuilt in a responsive way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/shanthipalani/embed/JjqExVB?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Journey
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Process:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Envisioning Enhancement:&lt;/strong&gt; Upon reviewing the HTML markup and objectives, I visualized ways to amplify its appeal and interactivity, ensuring seamless user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strategic Blueprinting:&lt;/strong&gt; I sketched a roadmap, delineating stages for each improvement, ranging from style infusion with CSS to functionality infusion via JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Artful Execution:&lt;/strong&gt; With a blend of precision and creativity, I executed enhancements incrementally, prioritizing user engagement and accessibility.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meticulous Refinement:&lt;/strong&gt; At each juncture, I meticulously refined the design and functionality, leveraging feedback loops and rigorous testing for refinement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comprehensive Documentation:&lt;/strong&gt; Finally, I encapsulated the journey in comprehensive documentation, elucidating the rationale behind each tweak and the cumulative impact on user delight.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learning:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Advanced Layout Techniques:&lt;/strong&gt; I honed skills in CSS Grids and Flexbox to sculpt responsive layouts, ensuring harmonious display across diverse screen dimensions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Eloquent Event Handling:&lt;/strong&gt; Through JavaScript, I mastered the orchestration of DOM events, seamlessly choreographing interactive elements like toggling night mode and modal unveilings.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Artistry of Animation:&lt;/strong&gt; Experimenting with the parallax effect unveiled a realm where CSS and JavaScript seamlessly converge to imbue interfaces with dynamism and allure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Proud Moments:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Innovative Solutions:&lt;/strong&gt; Crafting inventive avenues for features such as night mode, modal pop-ups, and the parallax effect fostered a sense of accomplishment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User-Centric Design:&lt;/strong&gt; Fusing aesthetics with accessibility, I endeavored to fashion an interface that beckons users with visual charm and navigational ease.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Next Steps:&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Unceasing Growth:&lt;/strong&gt; Fuelled by an insatiable appetite for learning, I aspire to delve deeper into advanced CSS techniques, explore emerging JavaScript frameworks, and delve into UX/UI design principles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feedback Integration:&lt;/strong&gt; I eagerly anticipate assimilating feedback, thereby fortifying future endeavors with insights garnered from real-world usage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exquisite Craftsmanship:&lt;/strong&gt; With each project, I aim to refine my craft, infusing it with finesse and flair, to craft digital experiences that captivate and inspire.&lt;/p&gt;

&lt;p&gt;Embracing the dynamism of web development, I relish the journey of continuous improvement and innovation, as I strive to craft interfaces that dazzle and delight users.&lt;/p&gt;

</description>
      <category>devchallenge</category>
      <category>frontendchallenge</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Mastering React Hooks: Best Practices for Efficient and Maintainable Code</title>
      <dc:creator>Shanthi's Dev Diary</dc:creator>
      <pubDate>Thu, 30 May 2024 17:44:53 +0000</pubDate>
      <link>https://dev.to/shantih_palani/mastering-react-hooks-best-practices-for-efficient-and-maintainable-code-4mp5</link>
      <guid>https://dev.to/shantih_palani/mastering-react-hooks-best-practices-for-efficient-and-maintainable-code-4mp5</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the ever-evolving landscape of React development, React Hooks have emerged as a powerful tool for managing state and side effects in functional components. With their introduction, developers have gained a more intuitive and concise way to write React code. However, as with any new feature, understanding and following best practices is essential for writing efficient and maintainable code. In this blog post, we'll dive deep into React Hooks and explore best practices to help you master them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Embrace Functional Components&lt;/strong&gt;&lt;br&gt;
Functional components are lightweight and easier to read. Here's a simple example demonstrating the transition from a class component to a functional component using Hooks.&lt;/p&gt;

&lt;p&gt;Class Component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Counter&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Increment&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Functional Component with Hooks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Increment&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Use Hooks Sparingly and Strategically&lt;/strong&gt;&lt;br&gt;
Avoid overcomplicating components with too many Hooks. Keep components focused and cohesive.&lt;/p&gt;

&lt;p&gt;Bad Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;([]);&lt;/span&gt;
  &lt;span class="c1"&gt;// Too many state variables can make the component hard to manage&lt;/span&gt;

  &lt;span class="c1"&gt;// logic...&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setText&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// logic...&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Follow the Rules of Hooks&lt;/strong&gt;&lt;br&gt;
Always call Hooks at the top level and never inside loops, conditions, or nested functions.&lt;/p&gt;

&lt;p&gt;Wrong Way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someCondition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// This will break the Rules of Hooks&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// logic...&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right Way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someCondition&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// use state&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// logic...&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Keep Hooks Simple and Readable&lt;/strong&gt;&lt;br&gt;
Break down complex logic into smaller, composable Hooks.&lt;/p&gt;

&lt;p&gt;Complex Hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useComplexLogic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// some complex logic&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;state2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simplified with Custom Hooks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useState1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// logic for state1&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state1&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useState2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// logic for state2&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state2&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState2&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useComplexLogic&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState2&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;5. Separate Concerns with Custom Hooks&lt;/strong&gt;&lt;br&gt;
Encapsulate reusable logic in custom Hooks.&lt;/p&gt;

&lt;p&gt;Custom Hook Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useFetch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setLoading&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;setLoading&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loading&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useFetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Optimize Performance&lt;/strong&gt;&lt;br&gt;
Use useMemo and useCallback to optimize performance and avoid unnecessary re-renders.&lt;/p&gt;

&lt;p&gt;Using useMemo and useCallback:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;expensiveCalculation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useMemo&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;acc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;acc&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useCallback&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="na"&gt;Sum&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;expensiveCalculation&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Increment&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Leverage useEffect Wisely&lt;/strong&gt;&lt;br&gt;
Manage side effects properly with useEffect.&lt;/p&gt;

&lt;p&gt;Data Fetching with Cleanup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isMounted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://api.example.com/data&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isMounted&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;isMounted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Cleanup&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Loading...&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React Hooks have revolutionized the way we write React components, offering a more elegant and functional approach to state management and side effects. By following best practices and leveraging the full potential of Hooks, you can write cleaner, more maintainable code and unlock new levels of productivity in your React development journey. Embrace the power of Hooks, but remember to use them wisely and responsibly to reap their full benefits. Happy hooking!&lt;/p&gt;

</description>
      <category>react</category>
      <category>reacthooks</category>
      <category>bestpractice</category>
      <category>hooks</category>
    </item>
  </channel>
</rss>
