<?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: Bismay.exe</title>
    <description>The latest articles on DEV Community by Bismay.exe (@bismay-exe).</description>
    <link>https://dev.to/bismay-exe</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif</url>
      <title>DEV Community: Bismay.exe</title>
      <link>https://dev.to/bismay-exe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bismay-exe"/>
    <language>en</language>
    <item>
      <title>🚀 Day 12 of Learning React: Understanding useEffect, Cleanup Functions, and API Calls</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Mon, 13 Jul 2026 21:53:19 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-12-of-learning-react-understanding-useeffect-cleanup-functions-and-api-calls-4d4g</link>
      <guid>https://dev.to/bismay-exe/day-12-of-learning-react-understanding-useeffect-cleanup-functions-and-api-calls-4d4g</guid>
      <description>&lt;p&gt;📌 &lt;strong&gt;Missed Day 11?&lt;/strong&gt; Last time I finally understood why React has Context API, how it solves prop drilling, and how multiple components can share the same state without passing props through every level. You can &lt;a href="https://dev.to/bismay-exe/day-11-of-learning-react-the-day-i-got-tired-of-passing-props-everywhere-context-api-explained-3ii0"&gt;&lt;strong&gt;read it here&lt;/strong&gt;&lt;/a&gt; and then come back. I'll wait. ☕️&lt;/p&gt;


&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-11-of-learning-react-the-day-i-got-tired-of-passing-props-everywhere-context-api-explained-3ii0" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 11 of Learning React: Finally Understanding React Context API (And Why Prop Drilling Gets Annoying)&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image" width="400" height="400"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-4136153" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt="" width="400" height="400"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-11-of-learning-react-the-day-i-got-tired-of-passing-props-everywhere-context-api-explained-3ii0" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 13&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-11-of-learning-react-the-day-i-got-tired-of-passing-props-everywhere-context-api-explained-3ii0" id="article-link-4136153"&gt;
          🚀 Day 11 of Learning React: Finally Understanding React Context API (And Why Prop Drilling Gets Annoying)
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-11-of-learning-react-the-day-i-got-tired-of-passing-props-everywhere-context-api-explained-3ii0" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-11-of-learning-react-the-day-i-got-tired-of-passing-props-everywhere-context-api-explained-3ii0#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              2&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;After spending the last few days learning about state, Context API, and sharing data between components, I thought I had a pretty solid understanding of React.&lt;/p&gt;

&lt;p&gt;Then today's lesson completely changed the way I think about rendering.&lt;/p&gt;

&lt;p&gt;I used to assume React somehow "knew" when it should fetch data, start a timer, or clean up resources.&lt;/p&gt;

&lt;p&gt;It doesn't.&lt;/p&gt;

&lt;p&gt;React only has one main responsibility:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Render the UI.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Anything that needs to happen &lt;strong&gt;after rendering&lt;/strong&gt; is considered a &lt;strong&gt;side effect&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And that's exactly why React gives us a hook called &lt;code&gt;useEffect()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;By the end of today's class, I realized &lt;code&gt;useEffect&lt;/code&gt; isn't just another hook to memorize.&lt;/p&gt;

&lt;p&gt;It's React's way of saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"If you want something to happen after rendering, tell me exactly when to do it."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's dive in. 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday's big question was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How can components share state without prop drilling?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I learned on Day 11:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🌐 Context API helps avoid prop drilling.&lt;/li&gt;
&lt;li&gt;📦 &lt;code&gt;createContext()&lt;/code&gt; creates a shared context.&lt;/li&gt;
&lt;li&gt;🏗️ The Provider makes shared data available.&lt;/li&gt;
&lt;li&gt;🎣 &lt;code&gt;useContext()&lt;/code&gt; lets components access that data directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, a completely different question came up.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How does React know when to run code after rendering? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🤔 The Mistake I Didn't Know I Was Making
&lt;/h2&gt;

&lt;p&gt;Suppose I have a function that fetches products from an API.&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;getData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&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="s2"&gt;https://fakestoreapi.com/products&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;setApiData&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="nx"&gt;data&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;My first instinct was simple.&lt;/p&gt;

&lt;p&gt;Just call it inside the component.&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;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="nf"&gt;getData&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 React&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;Looks harmless...&lt;/p&gt;

&lt;p&gt;Right?&lt;/p&gt;

&lt;p&gt;Not really.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔄 The Infinite Loop Problem
&lt;/h2&gt;

&lt;p&gt;Here's what actually happens.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Component Renders
        ↓
getData() Runs
        ↓
setApiData()
        ↓
State Updates
        ↓
Component Renders Again
        ↓
getData() Runs Again
        ↓
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React isn't doing anything wrong here.&lt;/p&gt;

&lt;p&gt;Every time the state changes...&lt;/p&gt;

&lt;p&gt;React renders again.&lt;/p&gt;

&lt;p&gt;Since &lt;code&gt;getData()&lt;/code&gt; is inside the component, it runs again too.&lt;/p&gt;

&lt;p&gt;Which updates the state.&lt;/p&gt;

&lt;p&gt;Which causes another render.&lt;/p&gt;

&lt;p&gt;Which calls &lt;code&gt;getData()&lt;/code&gt; again.&lt;/p&gt;

&lt;p&gt;And the cycle never ends.&lt;/p&gt;

&lt;p&gt;That was the moment I realized:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;React doesn't know that I only wanted to fetch the data once.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I have to tell it.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎣 Enter &lt;code&gt;useEffect()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;That's where today's star finally entered the picture.&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="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;getData&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;At first, this syntax looked strange.&lt;/p&gt;

&lt;p&gt;Especially that empty array at the end.&lt;/p&gt;

&lt;p&gt;What exactly is it doing?&lt;/p&gt;

&lt;p&gt;Turns out...&lt;/p&gt;

&lt;p&gt;That tiny array controls &lt;strong&gt;when&lt;/strong&gt; the effect should run.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚡ My First &lt;code&gt;useEffect&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Here's the exact code I used today.&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="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;getData&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;This tells React:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"After the component renders for the first time, run &lt;code&gt;getData()&lt;/code&gt;."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The important part is the empty dependency array.&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


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

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Run this effect only once after the initial render.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now the flow looks much cleaner.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Component Renders
        ↓
useEffect Runs
        ↓
API Request
        ↓
State Updates
        ↓
Component Re-renders
        ↓
Effect Doesn't Run Again ✅
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That single change completely solved the problem.&lt;/p&gt;


&lt;h2&gt;
  
  
  🌐 My First API Request with Axios
&lt;/h2&gt;

&lt;p&gt;Today's lesson also introduced me to &lt;strong&gt;Axios&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Before using it, I had to install it.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then importing it was straightforward.&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;axios&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;axios&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;Fetching data looked like this.&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;getData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &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;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&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="s2"&gt;https://fakestoreapi.com/products&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;setApiData&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="nx"&gt;data&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;This was my first time using Axios instead of the built-in &lt;code&gt;fetch()&lt;/code&gt; API.&lt;/p&gt;

&lt;p&gt;One thing I immediately noticed was how simple the response felt.&lt;/p&gt;

&lt;p&gt;With Axios, the actual data is already available inside:&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="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So after fetching the products, I simply updated my state.&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="nf"&gt;setApiData&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="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React re-rendered the component, and the products became available to display.&lt;/p&gt;

&lt;p&gt;That felt much cleaner than I expected.&lt;/p&gt;


&lt;h2&gt;
  
  
  📌 The Dependency Array Finally Made Sense
&lt;/h2&gt;

&lt;p&gt;If I'm being honest...&lt;/p&gt;

&lt;p&gt;The dependency array confused me more than &lt;code&gt;useEffect()&lt;/code&gt; itself.&lt;/p&gt;

&lt;p&gt;I kept wondering,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Why is React asking me for an array?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Eventually, I realized that the dependency array is simply React's way of knowing &lt;strong&gt;when an effect should run again.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are three common patterns.&lt;/p&gt;
&lt;h3&gt;
  
  
  1️⃣ No Dependency Array
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="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="s2"&gt;Running...&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;p&gt;This runs &lt;strong&gt;after every render.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Render
   ↓
Effect

Render
   ↓
Effect

Render
   ↓
Effect
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2️⃣ Empty Dependency Array
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="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="s2"&gt;Running...&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="p"&gt;[]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This runs only once.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;First Render
      ↓
Effect Runs ✅

Next Render
      ↓
Skipped
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3️⃣ Dependency Array with a Value
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="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="s2"&gt;Count changed&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now React watches &lt;code&gt;count&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;count&lt;/code&gt; changes...&lt;/p&gt;

&lt;p&gt;the effect runs again.&lt;/p&gt;

&lt;p&gt;If it doesn't...&lt;/p&gt;

&lt;p&gt;React skips it.&lt;/p&gt;

&lt;p&gt;After seeing all three together, I stopped memorizing them and started thinking about what React was actually doing.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Dependency Array&lt;/th&gt;
&lt;th&gt;When it Runs&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;No array&lt;/td&gt;
&lt;td&gt;After every render&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Only after the first render&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[count]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;After the first render and whenever &lt;code&gt;count&lt;/code&gt; changes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That tiny table made the dependency array much easier to remember.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤯 The Experiment That Finally Made Cleanup Click
&lt;/h2&gt;

&lt;p&gt;I thought today's biggest lesson would be fetching data from an API.&lt;/p&gt;

&lt;p&gt;Surprisingly, the thing that impressed me the most had nothing to do with APIs.&lt;/p&gt;

&lt;p&gt;It was understanding why React needs a &lt;strong&gt;cleanup function&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At first, I didn't understand why React lets us return a function inside &lt;code&gt;useEffect()&lt;/code&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="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="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="s2"&gt;About rendering...&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;()&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="s2"&gt;Cleanup&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="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;Why would I return a function from another function?&lt;/p&gt;

&lt;p&gt;It felt... unusual.&lt;/p&gt;

&lt;p&gt;Then I tried a small experiment.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⏱️ The Interval That Wouldn't Stop
&lt;/h2&gt;

&lt;p&gt;Inside my &lt;code&gt;About&lt;/code&gt; component, I created an interval.&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;let&lt;/span&gt; &lt;span class="nx"&gt;interval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setInterval&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="s2"&gt;Hey, I'm in About&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="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Every second, the console printed:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hey, I'm in About
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Exactly as expected.&lt;/p&gt;

&lt;p&gt;Then I switched from the &lt;strong&gt;About&lt;/strong&gt; component to the &lt;strong&gt;Contact&lt;/strong&gt; component.&lt;/p&gt;

&lt;p&gt;Since the About component disappeared...&lt;/p&gt;

&lt;p&gt;I expected the logging to stop.&lt;/p&gt;

&lt;p&gt;It didn't.&lt;/p&gt;

&lt;p&gt;The console kept printing:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hey, I'm in About
Hey, I'm in About
Hey, I'm in About
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That completely confused me.&lt;/p&gt;

&lt;p&gt;The component wasn't even on the screen anymore.&lt;/p&gt;

&lt;p&gt;So why was the interval still running?&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 React Removes Components... Not JavaScript
&lt;/h2&gt;

&lt;p&gt;This was probably the biggest realization of today's lesson.&lt;/p&gt;

&lt;p&gt;When React removes a component from the screen...&lt;/p&gt;

&lt;p&gt;it only removes the component itself.&lt;/p&gt;

&lt;p&gt;It &lt;strong&gt;doesn't automatically stop&lt;/strong&gt; timers, intervals, or event listeners created by JavaScript.&lt;/p&gt;

&lt;p&gt;Those things continue running unless I stop them myself.&lt;/p&gt;

&lt;p&gt;That's exactly why the cleanup function exists.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧹 The Cleanup Function
&lt;/h2&gt;

&lt;p&gt;Here's the version that fixed everything.&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="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;interval&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setInterval&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="s2"&gt;Hey, I'm in About&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="mi"&gt;1000&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="nf"&gt;clearInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;interval&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here's how I visualize it now:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;About Component Mounts
        ↓
Interval Starts
        ↓
User Switches Page
        ↓
Component Unmounts
        ↓
Cleanup Function Runs
        ↓
Interval Stops ✅
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That finally made the purpose of cleanup click for me.&lt;/p&gt;

&lt;p&gt;React isn't cleaning things automatically.&lt;/p&gt;

&lt;p&gt;It's simply giving me one last chance to clean up anything my component created before it disappears.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔄 Mount, Re-render, and Unmount
&lt;/h2&gt;

&lt;p&gt;Another thing I kept hearing today was:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Mount&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Re-render&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Unmount&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At first, they sounded like complicated React terms.&lt;/p&gt;

&lt;p&gt;But after today's examples, I started thinking about them much more simply.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Mount
↓
Component appears for the first time.

Re-render
↓
Component runs again because state or props changed.

Unmount
↓
Component is removed from the screen.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That also explained why the cleanup function runs during &lt;strong&gt;unmounting&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;React is basically saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Your component is leaving. If you started anything, now is the time to stop it."&lt;/p&gt;
&lt;/blockquote&gt;


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

&lt;p&gt;This is how I picture &lt;code&gt;useEffect()&lt;/code&gt; now.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Component Renders
        ↓
React Updates the UI
        ↓
useEffect Runs
        ↓
Side Effect Happens
(API Call, Timer, Event Listener...)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And if the component is removed...&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Component Unmounts
        ↓
Cleanup Function Runs
        ↓
Resources Are Released
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Thinking about it this way made today's lesson much easier to remember.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🎣 &lt;code&gt;useEffect()&lt;/code&gt; lets React run code &lt;strong&gt;after rendering&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;🌐 API requests are a common use case for &lt;code&gt;useEffect()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;📦 The dependency array controls &lt;strong&gt;when&lt;/strong&gt; an effect runs.&lt;/li&gt;
&lt;li&gt;⚡ An empty dependency array (&lt;code&gt;[]&lt;/code&gt;) runs the effect only once after the initial render.&lt;/li&gt;
&lt;li&gt;🧹 Cleanup functions stop things like intervals and event listeners before a component unmounts.&lt;/li&gt;
&lt;li&gt;🧠 React renders the UI—but side effects are still my responsibility.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through &lt;strong&gt;React Cohort 3.0&lt;/strong&gt; by &lt;strong&gt;Devendra Dhote&lt;/strong&gt; at Sheriyans Coding School.&lt;/p&gt;

&lt;p&gt;This article is based on my own class notes, code experiments, and understanding. Writing these posts helps me reinforce what I've learned, and hopefully makes things a little easier for other beginners too.&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate any corrections in the comments. 😊&lt;/p&gt;


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

&lt;p&gt;Today's lesson completely changed how I think about React.&lt;/p&gt;

&lt;p&gt;Before today's class, I thought &lt;code&gt;useEffect()&lt;/code&gt; was mostly for fetching data from APIs.&lt;/p&gt;

&lt;p&gt;By the end of the lesson, I realized API calls are just one example of a side effect.&lt;/p&gt;

&lt;p&gt;The real purpose of &lt;code&gt;useEffect()&lt;/code&gt; is much bigger.&lt;/p&gt;

&lt;p&gt;It's React's way of letting us run code &lt;strong&gt;after rendering&lt;/strong&gt;, while also giving us a chance to clean everything up when a component disappears.&lt;/p&gt;

&lt;p&gt;The cleanup function was my favorite part of today's lesson.&lt;/p&gt;

&lt;p&gt;Watching an interval continue running after a component disappeared was confusing at first, but once I understood why cleanup exists, everything finally clicked.&lt;/p&gt;

&lt;p&gt;I'm starting to notice something interesting about React.&lt;/p&gt;

&lt;p&gt;Every hook I've learned so far exists because it solves a very specific problem.&lt;/p&gt;

&lt;p&gt;The more I understand those problems, the more React itself starts making sense.&lt;/p&gt;

&lt;p&gt;See you on &lt;strong&gt;Day 13!&lt;/strong&gt; 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;What confused you the most when you first learned &lt;code&gt;useEffect()&lt;/code&gt;? Was it the dependency array, the cleanup function, or simply knowing when to use it? I'd love to hear your experience in the comments. 😊&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;strong&gt;GitHub&lt;/strong&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;






&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 11 of Learning React: Finally Understanding React Context API (And Why Prop Drilling Gets Annoying)</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Mon, 13 Jul 2026 19:17:06 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-11-of-learning-react-the-day-i-got-tired-of-passing-props-everywhere-context-api-explained-3ii0</link>
      <guid>https://dev.to/bismay-exe/day-11-of-learning-react-the-day-i-got-tired-of-passing-props-everywhere-context-api-explained-3ii0</guid>
      <description>&lt;p&gt;📌 &lt;strong&gt;Missed Day 10?&lt;/strong&gt; Last time I built my first CRUD application using React Hook Form, Local Storage, and &lt;code&gt;nanoid()&lt;/code&gt;. It was the first project where I could create, update, and delete users while keeping the data even after refreshing the page. You can &lt;a href="https://dev.to/bismay-exe/day-10-of-learning-react-my-react-form-finally-became-a-real-crud-app-local-storage-create-49i4"&gt;&lt;strong&gt;read it here&lt;/strong&gt;&lt;/a&gt; and then come back. I'll wait. ☕️*&lt;/p&gt;


&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-10-of-learning-react-my-react-form-finally-became-a-real-crud-app-local-storage-create-49i4" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 10 of Learning React: My React Form Finally Became a Real CRUD App (Local Storage, Create, Update &amp;amp; Delete)&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image" width="400" height="400"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-4136059" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt="" width="400" height="400"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-10-of-learning-react-my-react-form-finally-became-a-real-crud-app-local-storage-create-49i4" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 13&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-10-of-learning-react-my-react-form-finally-became-a-real-crud-app-local-storage-create-49i4" id="article-link-4136059"&gt;
          🚀 Day 10 of Learning React: My React Form Finally Became a Real CRUD App (Local Storage, Create, Update &amp;amp; Delete)
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-10-of-learning-react-my-react-form-finally-became-a-real-crud-app-local-storage-create-49i4" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-10-of-learning-react-my-react-form-finally-became-a-real-crud-app-local-storage-create-49i4#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;Yesterday, I was feeling pretty confident.&lt;/p&gt;

&lt;p&gt;I knew how to lift state up.&lt;/p&gt;

&lt;p&gt;If two components needed the same data, I could simply move the state to their common parent and pass it down using props.&lt;/p&gt;

&lt;p&gt;Problem solved.&lt;/p&gt;

&lt;p&gt;...or at least that's what I thought.&lt;/p&gt;

&lt;p&gt;Today I realized that lifting state isn't always enough.&lt;/p&gt;

&lt;p&gt;As applications grow, passing the same props through multiple components starts becoming frustrating.&lt;/p&gt;

&lt;p&gt;That's exactly why React gives us &lt;strong&gt;Context API&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Here's what I already knew before today's lesson.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State can live in a parent component.&lt;/li&gt;
&lt;li&gt;Child components receive data through props.&lt;/li&gt;
&lt;li&gt;Multiple components can share the same state by lifting it up.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That worked well for small examples.&lt;/p&gt;

&lt;p&gt;But then I started wondering...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What happens when the component that needs the data is several levels deeper?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🤔 The Problem That Lifting State Couldn't Solve
&lt;/h2&gt;

&lt;p&gt;On Day 7, I learned that components can share data by lifting state up.&lt;/p&gt;

&lt;p&gt;That works really well...&lt;/p&gt;

&lt;p&gt;until the component that needs the data is buried several levels deep.&lt;/p&gt;

&lt;p&gt;Imagine this component tree:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App
 ├── Component A
      ├── Component B
            ├── Component C
                  └── Component D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now suppose &lt;strong&gt;Component D&lt;/strong&gt; needs some data that's stored in &lt;strong&gt;App&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Without Context API, the data has to travel through every intermediate component.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App
 ↓
Component A
 ↓
Component B
 ↓
Component C
 ↓
Component D
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Even though Components A, B, and C don't actually use the data, they still have to receive it as props and pass it to the next component.&lt;/p&gt;

&lt;p&gt;That pattern is called &lt;strong&gt;Prop Drilling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For a small application, it isn't a huge problem.&lt;/p&gt;

&lt;p&gt;But once the component tree starts growing, passing the same props through layer after layer quickly becomes difficult to manage.&lt;/p&gt;

&lt;p&gt;That's the exact problem Context API is designed to solve.&lt;/p&gt;


&lt;h2&gt;
  
  
  🚀 Enter Context API
&lt;/h2&gt;

&lt;p&gt;This is where Context API comes in.&lt;/p&gt;

&lt;p&gt;Instead of sending props through every component,&lt;/p&gt;

&lt;p&gt;React lets us create a &lt;strong&gt;shared place&lt;/strong&gt; where multiple components can access the &lt;strong&gt;same data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Then any component inside that tree can access it whenever it needs to.&lt;/p&gt;

&lt;p&gt;My favorite way to think about it is this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;I started thinking of Context API as a shared storage room that every component inside the same application can access.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No more passing keys from one room to another.&lt;/p&gt;


&lt;h2&gt;
  
  
  🏗️ Creating a Context
&lt;/h2&gt;

&lt;p&gt;The first thing I learned was that React needs a Context object.&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createContext&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyShop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;createContext()&lt;/code&gt; creates the shared context.&lt;/p&gt;

&lt;p&gt;At this point, it doesn't contain any data yet.&lt;/p&gt;

&lt;p&gt;It's simply preparing a place where shared data can live.&lt;/p&gt;


&lt;h2&gt;
  
  
  📦 The Provider
&lt;/h2&gt;

&lt;p&gt;Creating the context isn't enough.&lt;/p&gt;

&lt;p&gt;React also needs to know &lt;strong&gt;which components should have access to it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's where the Provider comes in.&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;MyShop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt;
  &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;isCartOpen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;setIsCartOpen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;cartItems&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;setCartItems&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&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="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;MyShop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&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;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmaleyqpkx20kf0yopi2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fmaleyqpkx20kf0yopi2z.png" alt="Context Provider in my project" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The Provider makes shared state available to every component inside it.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The Provider wraps part (or all) of the application.&lt;/p&gt;

&lt;p&gt;Everything inside it can now access the shared values.&lt;/p&gt;

&lt;p&gt;Instead of manually passing props everywhere,&lt;/p&gt;

&lt;p&gt;React makes them available automatically.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎣 Accessing Shared Data With &lt;code&gt;useContext()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Now comes the easiest part.&lt;/p&gt;

&lt;p&gt;Any child component can read shared data using &lt;code&gt;useContext()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;setCartItems&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MyShop&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;/p&gt;

&lt;p&gt;No prop drilling.&lt;/p&gt;

&lt;p&gt;No forwarding props through multiple components.&lt;/p&gt;

&lt;p&gt;The component simply asks React for the data.&lt;/p&gt;

&lt;p&gt;I honestly thought,&lt;/p&gt;

&lt;p&gt;"Wait... that's all?"&lt;/p&gt;

&lt;p&gt;It felt much simpler than I expected.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚙️ Putting Everything Together
&lt;/h2&gt;

&lt;p&gt;After learning each piece individually, I realized Context API follows a pretty simple workflow.&lt;/p&gt;

&lt;p&gt;First, create the context.&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyShop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then wrap the part of the application that should have access to the shared data.&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;MyShop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;cartItems&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCartItems&lt;/span&gt; &lt;span class="p"&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;App&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;MyShop&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Provider&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;Finally, inside any child component, access that data with &lt;code&gt;useContext()&lt;/code&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;cartItems&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MyShop&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 really all there is to it.&lt;/p&gt;

&lt;p&gt;Instead of memorizing three different APIs, I started thinking of Context API as one simple flow.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create Context
        ↓
Wrap Components with Provider
        ↓
Store Shared Values in value
        ↓
Read Them Anywhere Using useContext()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That mental model helped everything click for me.&lt;/p&gt;


&lt;h2&gt;
  
  
  🛒 My Shopping Cart Project
&lt;/h2&gt;

&lt;p&gt;Today's class wasn't just theory.&lt;/p&gt;

&lt;p&gt;We built a small shopping cart application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fute4urygu6ko4besju7b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fute4urygu6ko4besju7b.png" alt="My shopping cart project before adding products" width="755" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;My shopping cart project before adding any products to the cart.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The application had three main parts:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App
 ├── Navbar
 ├── Product Cards
 └── Cart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The interesting part was this.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;ProductCard&lt;/strong&gt; component needed to add items to the cart.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Cart&lt;/strong&gt; component needed to display those same items.&lt;/p&gt;

&lt;p&gt;Instead of passing cart data through several components,&lt;/p&gt;

&lt;p&gt;both of them simply accessed the same Context.&lt;/p&gt;

&lt;p&gt;Adding a product looked like this:&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="nf"&gt;setCartItems&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And displaying the cart was just:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;cartItems&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MyShop&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgj3cl9xwhsmghlcryc1r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fgj3cl9xwhsmghlcryc1r.png" alt="Cart after adding a product" width="756" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;After clicking **Add to Cart&lt;/em&gt;&lt;em&gt;, the product is instantly available in the Cart because both components are reading and updating the same Context.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Both components were reading and updating the exact same state.&lt;/p&gt;

&lt;p&gt;I started picturing it like this.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ProductCard
      │
      │ Add Item
      ▼
Shared Context
      ▲
      │ Read Items
Cart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Neither component needed to pass props to the other.&lt;/p&gt;

&lt;p&gt;They simply talked to the same Context.&lt;/p&gt;

&lt;p&gt;That was the moment I understood why Context API exists.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔄 How Data Flows
&lt;/h2&gt;

&lt;p&gt;Here's the mental model I built while learning today.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;createContext()
        │
        ▼
Provider stores shared data
        │
        ▼
Components call useContext()
        │
        ▼
Access the same shared values
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flqstsil6fgjpm9p13ou3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flqstsil6fgjpm9p13ou3.png" alt="Context API Diagram" width="736" height="482"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;This is the mental model I built while learning Context API.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Once I pictured it this way,&lt;/p&gt;

&lt;p&gt;Context API became much easier to understand.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤔 Is Context API State Management?
&lt;/h2&gt;

&lt;p&gt;At first, I assumed Context API was React's built-in state management solution.&lt;/p&gt;

&lt;p&gt;After experimenting with it, I realized that's not really its job.&lt;/p&gt;

&lt;p&gt;The actual state still comes from hooks like &lt;code&gt;useState()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Context API simply makes that state available to multiple components without passing props through every level of the component tree.&lt;/p&gt;

&lt;p&gt;That small distinction cleared up a misunderstanding I had during today's lesson.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤯 The Moment It Finally Clicked
&lt;/h2&gt;

&lt;p&gt;At first, I kept thinking,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Couldn't I just keep passing props?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Technically...&lt;/p&gt;

&lt;p&gt;Yes.&lt;/p&gt;

&lt;p&gt;React wouldn't stop me.&lt;/p&gt;

&lt;p&gt;But then I imagined adding five or six more components between &lt;code&gt;App&lt;/code&gt; and &lt;code&gt;Cart&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Every one of those components would have to accept props they didn't even use.&lt;/p&gt;

&lt;p&gt;That's when I finally understood that Context API isn't about making React do something impossible.&lt;/p&gt;

&lt;p&gt;It's about making the code easier to work with as an application grows.&lt;/p&gt;

&lt;p&gt;That small shift completely changed how I think about sharing data between components.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Props work well until they have to travel through many components.&lt;/li&gt;
&lt;li&gt;Passing props through intermediate components is called &lt;strong&gt;Prop Drilling&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;createContext()&lt;/code&gt; creates a shared context.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Provider&lt;/strong&gt; makes shared values available to child components.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useContext()&lt;/code&gt; lets any component read those values directly.&lt;/li&gt;
&lt;li&gt;Context API helps share state—it doesn't replace &lt;code&gt;useState()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through &lt;strong&gt;React Cohort 3.0&lt;/strong&gt; by &lt;strong&gt;Devendra Dhote&lt;/strong&gt; at Sheriyans Coding School.&lt;/p&gt;

&lt;p&gt;This article is based on my own class notes, experiments, and understanding. It's written entirely in my own words to reinforce what I learned.&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate any corrections in the comments.&lt;/p&gt;


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

&lt;p&gt;Today's lesson answered a question I didn't even know I had.&lt;/p&gt;

&lt;p&gt;On Day 7, lifting state up felt like the solution for sharing data.&lt;/p&gt;

&lt;p&gt;Today I learned that it isn't always the final solution.&lt;/p&gt;

&lt;p&gt;When data needs to travel through several layers of components, Context API gives React a much cleaner way to share it.&lt;/p&gt;

&lt;p&gt;I'm sure I'll understand it even better as I build bigger projects, but for now, I finally understand &lt;strong&gt;why Context API exists&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And that feels like a big step forward in my React journey.&lt;/p&gt;

&lt;p&gt;Tomorrow I'll continue exploring React and see what comes next.&lt;/p&gt;

&lt;p&gt;See you on &lt;strong&gt;Day 12!&lt;/strong&gt; 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;When did Context API finally "click" for you? Was it when you first learned about prop drilling, or when you built a real project that needed shared state?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 10 of Learning React: My React Form Finally Became a Real CRUD App (Local Storage, Create, Update &amp; Delete)</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Mon, 13 Jul 2026 18:55:53 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-10-of-learning-react-my-react-form-finally-became-a-real-crud-app-local-storage-create-49i4</link>
      <guid>https://dev.to/bismay-exe/day-10-of-learning-react-my-react-form-finally-became-a-real-crud-app-local-storage-create-49i4</guid>
      <description>&lt;p&gt;📌 &lt;em&gt;Missed Day 9? I explored how React Hook Form handles validation, why the &lt;code&gt;errors&lt;/code&gt; object exists, and how &lt;code&gt;register()&lt;/code&gt; and &lt;code&gt;handleSubmit()&lt;/code&gt; work together to prevent invalid form submissions. You can **read it here&lt;/em&gt;* and then come back. I'll wait. ☕️*&lt;/p&gt;


&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-9-of-learning-react-why-every-form-needs-validation-react-hook-form-made-it-surprisingly-4d1k" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 9 of Learning React: Why Every Form Needs Validation (React Hook Form Made It Surprisingly Easy)&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image" width="400" height="400"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-4135924" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt="" width="400" height="400"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-9-of-learning-react-why-every-form-needs-validation-react-hook-form-made-it-surprisingly-4d1k" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 13&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-9-of-learning-react-why-every-form-needs-validation-react-hook-form-made-it-surprisingly-4d1k" id="article-link-4135924"&gt;
          🚀 Day 9 of Learning React: Why Every Form Needs Validation (React Hook Form Made It Surprisingly Easy)
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-9-of-learning-react-why-every-form-needs-validation-react-hook-form-made-it-surprisingly-4d1k" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-9-of-learning-react-why-every-form-needs-validation-react-hook-form-made-it-surprisingly-4d1k#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;Yesterday, I finally built a form that could collect user information.&lt;/p&gt;

&lt;p&gt;It worked.&lt;/p&gt;

&lt;p&gt;I could enter a name, email, mobile number, and image URL.&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Add User&lt;/strong&gt;...&lt;/p&gt;

&lt;p&gt;The new user appeared on the screen.&lt;/p&gt;

&lt;p&gt;Everything looked perfect.&lt;/p&gt;

&lt;p&gt;Until I refreshed the page.&lt;/p&gt;

&lt;p&gt;Every single user disappeared.&lt;/p&gt;

&lt;p&gt;😐&lt;/p&gt;

&lt;p&gt;That's when I realized something.&lt;/p&gt;

&lt;p&gt;React wasn't losing my data...&lt;/p&gt;

&lt;p&gt;It was doing exactly what I asked it to do.&lt;/p&gt;

&lt;p&gt;The problem was that I was only storing everything in &lt;strong&gt;state&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Today, I learned how to make my application actually remember data—even after refreshing the browser.&lt;/p&gt;

&lt;p&gt;And by the end of the class, my simple form had turned into my first &lt;strong&gt;CRUD application.&lt;/strong&gt; 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday's big question was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How can I make forms smarter with validation?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I learned on Day 9:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ React Hook Form simplifies form handling.&lt;/li&gt;
&lt;li&gt;⚠️ Validation rules prevent invalid input.&lt;/li&gt;
&lt;li&gt;📩 &lt;code&gt;errors&lt;/code&gt; stores validation messages.&lt;/li&gt;
&lt;li&gt;📝 &lt;code&gt;register()&lt;/code&gt; connects inputs to React Hook Form.&lt;/li&gt;
&lt;li&gt;🚀 &lt;code&gt;handleSubmit()&lt;/code&gt; only runs when validation passes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, we're answering a different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How can my application actually remember user data? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  💾 The Problem With React State
&lt;/h2&gt;

&lt;p&gt;At first, I stored my users like this:&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setUsers&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Whenever I submitted the form, a new user appeared instantly.&lt;/p&gt;

&lt;p&gt;Everything seemed fine.&lt;/p&gt;

&lt;p&gt;Until I pressed refresh.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Add User
     ↓
User Appears
     ↓
Refresh Browser
     ↓
Everything Disappears 😶
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That wasn't React making a mistake.&lt;/p&gt;

&lt;p&gt;It was simply because React state only lives while the application is running.&lt;/p&gt;

&lt;p&gt;Refreshing the page starts everything from scratch.&lt;/p&gt;


&lt;h2&gt;
  
  
  📦 Enter Local Storage
&lt;/h2&gt;

&lt;p&gt;That's where I discovered &lt;strong&gt;Local Storage&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Unlike React state, Local Storage is built into the browser.&lt;/p&gt;

&lt;p&gt;It stores data even after refreshing the page.&lt;/p&gt;

&lt;p&gt;Instead of starting with an empty array, I initialized my state like this:&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setUsers&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="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;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;users&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="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;At first, that line looked intimidating.&lt;/p&gt;

&lt;p&gt;But after breaking it down, it made perfect sense.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧩 Breaking It Down
&lt;/h2&gt;

&lt;p&gt;First:&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="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;users&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;tries to read previously saved users.&lt;/p&gt;

&lt;p&gt;But Local Storage stores everything as &lt;strong&gt;strings&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That's why React can't use it directly.&lt;/p&gt;

&lt;p&gt;So I used:&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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;to convert the string back into an array of objects.&lt;/p&gt;

&lt;p&gt;Finally:&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="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;acts as a fallback.&lt;/p&gt;

&lt;p&gt;If no users exist yet, React simply starts with an empty array.&lt;/p&gt;


&lt;h2&gt;
  
  
  💾 Saving Users
&lt;/h2&gt;

&lt;p&gt;Loading data is only half of the story.&lt;/p&gt;

&lt;p&gt;Whenever I created a new user, I also needed to save it.&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="nx"&gt;localStorage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setItem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;"&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;arr&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;This line does the opposite.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;JavaScript Object
        ↓
JSON.stringify()
        ↓
String
        ↓
Saved in Local Storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, even after refreshing the page...&lt;/p&gt;

&lt;p&gt;My users were still there.&lt;/p&gt;

&lt;p&gt;That was a really satisfying moment.&lt;/p&gt;


&lt;h2&gt;
  
  
  🆔 Every User Needs a Unique Identity
&lt;/h2&gt;

&lt;p&gt;While building the CRUD application, I ran into another small but important problem.&lt;/p&gt;

&lt;p&gt;Every user needed a way to be uniquely identified.&lt;/p&gt;

&lt;p&gt;Without a unique ID, React wouldn't know exactly which user I wanted to update or delete.&lt;/p&gt;

&lt;p&gt;There are several ways to generate unique IDs. Some common options are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using a database-generated ID&lt;/li&gt;
&lt;li&gt;JavaScript's built-in &lt;code&gt;crypto.randomUUID()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The popular &lt;code&gt;uuid&lt;/code&gt; package&lt;/li&gt;
&lt;li&gt;The lightweight &lt;strong&gt;nanoid&lt;/strong&gt; package&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this project, I used &lt;strong&gt;nanoid&lt;/strong&gt; because it's simple, lightweight, and generates unique IDs with very little setup.&lt;/p&gt;
&lt;h3&gt;
  
  
  📦 Installing Nano ID
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;nanoid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After installing it, I imported it into my component:&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;nanoid&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;nanoid&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;Whenever I created a new user, I generated a unique ID like this:&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;newUser&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;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;nanoid&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;Now every user has its own unique identifier.&lt;/p&gt;

&lt;p&gt;That ID becomes incredibly useful later.&lt;/p&gt;

&lt;p&gt;When I click &lt;strong&gt;Update&lt;/strong&gt; or &lt;strong&gt;Delete&lt;/strong&gt;, React can easily find the correct user by comparing IDs instead of relying on things like the user's name or their position in the array.&lt;/p&gt;

&lt;p&gt;It might seem like a tiny detail, but adding unique IDs makes managing collections of data much more reliable—especially as applications grow larger.&lt;/p&gt;


&lt;h2&gt;
  
  
  ❌ Deleting Users
&lt;/h2&gt;

&lt;p&gt;The next feature I added was deleting users.&lt;/p&gt;

&lt;p&gt;The logic turned out to be surprisingly clean.&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;filteredUsers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&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="o"&gt;=&amp;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;id&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The flow looks like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Click Delete
      ↓
Remove Matching User
      ↓
Update State
      ↓
Update Local Storage
      ↓
UI Updates ✨
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;One click...&lt;/p&gt;

&lt;p&gt;And the selected card disappeared.&lt;/p&gt;


&lt;h2&gt;
  
  
  ✏️ Reusing the Same Form for Updates
&lt;/h2&gt;

&lt;p&gt;This was probably the coolest part of today's project.&lt;/p&gt;

&lt;p&gt;My first thought was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Updating a user probably needs another form."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It turns out...&lt;/p&gt;

&lt;p&gt;It didn't.&lt;/p&gt;

&lt;p&gt;I reused the exact same form for both &lt;strong&gt;creating&lt;/strong&gt; and &lt;strong&gt;updating&lt;/strong&gt; users.&lt;/p&gt;

&lt;p&gt;That felt much cleaner than building two separate forms.&lt;/p&gt;


&lt;h2&gt;
  
  
  📋 Filling the Form Automatically
&lt;/h2&gt;

&lt;p&gt;When I clicked &lt;strong&gt;Update&lt;/strong&gt;, I passed the selected user's data into the form.&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="nx"&gt;defaultValues&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;updatedData&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That tiny line made React Hook Form automatically fill every input.&lt;/p&gt;

&lt;p&gt;Instead of seeing empty fields...&lt;/p&gt;

&lt;p&gt;I immediately saw the existing user's information.&lt;/p&gt;

&lt;p&gt;It felt like the form already knew what I wanted to edit.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔄 Updating Only One User
&lt;/h2&gt;

&lt;p&gt;Saving the updated data was another interesting part.&lt;/p&gt;

&lt;p&gt;Instead of replacing the whole array, I only replaced the matching user.&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="nf"&gt;setUsers&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&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;user&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;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;updatedData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&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;data&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="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here's how I visualize it:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users Array
      ↓
Loop Through Every User
      ↓
Matching ID?
      ↓
YES ✅ Replace It

NO ❌ Keep It
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Only one object changes.&lt;/p&gt;

&lt;p&gt;Everything else stays exactly the same.&lt;/p&gt;

&lt;p&gt;That made &lt;code&gt;map()&lt;/code&gt; feel much more practical than when I first learned it.&lt;/p&gt;


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

&lt;p&gt;Today's project finally connected a lot of concepts I'd learned over the past few days.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Fill Form
      ↓
React Hook Form Validates
      ↓
User Added
      ↓
Save in State
      ↓
Save in Local Storage
      ↓
Render User Cards
      ↓
Update or Delete User
      ↓
UI Updates Automatically ✨
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Seeing everything work together made the project feel much more like a real application instead of isolated React examples.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;💾 React state disappears after a refresh, but Local Storage doesn't.&lt;/li&gt;
&lt;li&gt;📦 &lt;code&gt;JSON.parse()&lt;/code&gt; converts stored strings back into JavaScript objects.&lt;/li&gt;
&lt;li&gt;📝 &lt;code&gt;JSON.stringify()&lt;/code&gt; prepares objects before saving them.&lt;/li&gt;
&lt;li&gt;🆔 &lt;code&gt;nanoid()&lt;/code&gt; makes it easy to generate unique IDs.&lt;/li&gt;
&lt;li&gt;✏️ The same form can be reused for both creating and updating users.&lt;/li&gt;
&lt;li&gt;🔄 &lt;code&gt;map()&lt;/code&gt; makes updating a single object inside an array surprisingly clean.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the React Cohort 3.0 by Devendra Dhote at Sheriyans Coding School.&lt;/p&gt;

&lt;p&gt;This article is based on my own class notes, code experiments, and understanding after today's session. Writing these posts helps me reinforce what I've learned, and hopefully helps other beginners following a similar path.&lt;/p&gt;

&lt;p&gt;If I've misunderstood anything, I'd genuinely appreciate corrections in the comments. 😊&lt;/p&gt;


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

&lt;p&gt;Today's project felt different from the previous ones.&lt;/p&gt;

&lt;p&gt;Instead of learning a single React concept, I finally saw several concepts working together.&lt;/p&gt;

&lt;p&gt;State stored the data.&lt;/p&gt;

&lt;p&gt;React Hook Form handled user input.&lt;/p&gt;

&lt;p&gt;Local Storage made the data survive page refreshes.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;map()&lt;/code&gt; updated individual users.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;filter()&lt;/code&gt; removed them.&lt;/p&gt;

&lt;p&gt;For the first time, it felt like I wasn't just writing React code—I was building something that behaved like a real application.&lt;/p&gt;

&lt;p&gt;Tomorrow's topic is &lt;strong&gt;Context API&lt;/strong&gt;, and I'm curious to see how React lets components share data without passing props through every level.&lt;/p&gt;

&lt;p&gt;See you on Day 11! 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;When you built your first CRUD application, what feature felt the most satisfying to implement—Create, Update, Delete, or saving data with Local Storage?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 9 of Learning React: Why Every Form Needs Validation (React Hook Form Made It Surprisingly Easy)</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Mon, 13 Jul 2026 18:24:32 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-9-of-learning-react-why-every-form-needs-validation-react-hook-form-made-it-surprisingly-4d1k</link>
      <guid>https://dev.to/bismay-exe/day-9-of-learning-react-why-every-form-needs-validation-react-hook-form-made-it-surprisingly-4d1k</guid>
      <description>&lt;p&gt;📌 &lt;em&gt;Missed Day 8? I explored why React doesn't usually let us work directly with the DOM, how &lt;code&gt;useRef()&lt;/code&gt; gives us access to real DOM elements, and why React Hook Form makes handling forms much cleaner. You can **read it here&lt;/em&gt;* and then come back. I'll wait. ☕️*&lt;/p&gt;


&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-8-of-learning-react-why-doesnt-react-use-the-dom-directly-understanding-useref-react-2c7i" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 8 of Learning React: Why Doesn't React Use the DOM Directly? Understanding useRef() &amp;amp; React Hook Form&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-4135689" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-8-of-learning-react-why-doesnt-react-use-the-dom-directly-understanding-useref-react-2c7i" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 13&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-8-of-learning-react-why-doesnt-react-use-the-dom-directly-understanding-useref-react-2c7i" id="article-link-4135689"&gt;
          🚀 Day 8 of Learning React: Why Doesn't React Use the DOM Directly? Understanding useRef() &amp;amp; React Hook Form
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-8-of-learning-react-why-doesnt-react-use-the-dom-directly-understanding-useref-react-2c7i" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;3&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-8-of-learning-react-why-doesnt-react-use-the-dom-directly-understanding-useref-react-2c7i#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              1&lt;span class="hidden s:inline"&gt;&amp;nbsp;comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;Yesterday, I finally understood how React Hook Form simplified form handling.&lt;/p&gt;

&lt;p&gt;I thought that was the hard part.&lt;/p&gt;

&lt;p&gt;Turns out...&lt;/p&gt;

&lt;p&gt;Building the form was only half the job.&lt;/p&gt;

&lt;p&gt;Because no matter how beautiful a form looks, there's always one problem.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Users can type literally anything.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;An empty name.&lt;/p&gt;

&lt;p&gt;An invalid email.&lt;/p&gt;

&lt;p&gt;A phone number with only five digits.&lt;/p&gt;

&lt;p&gt;Without validation, my application would happily accept all of them.&lt;/p&gt;

&lt;p&gt;Today's lesson wasn't about making forms prettier.&lt;/p&gt;

&lt;p&gt;It was about making them &lt;strong&gt;smarter&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's dive in. 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday's big question was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Why doesn't React use the DOM directly?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I learned on Day 8:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🎣 &lt;code&gt;useRef()&lt;/code&gt; lets React keep references to DOM elements.&lt;/li&gt;
&lt;li&gt;🌳 React usually works with the Virtual DOM instead of the Real DOM.&lt;/li&gt;
&lt;li&gt;📝 React Hook Form makes handling forms much cleaner.&lt;/li&gt;
&lt;li&gt;🚀 &lt;code&gt;register()&lt;/code&gt;, &lt;code&gt;handleSubmit()&lt;/code&gt;, and &lt;code&gt;reset()&lt;/code&gt; reduce repetitive form logic.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today we're answering a different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How do we stop users from submitting invalid data? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🤔 A Form That Accepts Everything...
&lt;/h2&gt;

&lt;p&gt;At first, my form looked perfectly fine.&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="nt"&gt;input&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;register&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="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="nt"&gt;input&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&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;Users could type...&lt;/p&gt;

&lt;p&gt;Click &lt;strong&gt;Submit&lt;/strong&gt;...&lt;/p&gt;

&lt;p&gt;Everything worked.&lt;/p&gt;

&lt;p&gt;Or at least...&lt;/p&gt;

&lt;p&gt;It looked like it worked.&lt;/p&gt;

&lt;p&gt;Then I started thinking about something.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4uwtnsmhu7ey1fc1ebof.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4uwtnsmhu7ey1fc1ebof.png" alt="React Hook Form before validation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The form before submission. At this point, nothing prevents users from entering invalid data.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What if someone submitted this?&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Name:
"          "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Or this?&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Email:
abc123
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Or even left every field empty?&lt;/p&gt;

&lt;p&gt;My form would still accept it.&lt;/p&gt;

&lt;p&gt;That's when I realized something.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Collecting user input is easy. Trusting it is the difficult part.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  🚫 My First Validation Rule
&lt;/h2&gt;

&lt;p&gt;The first validation rule I added was surprisingly simple.&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="nf"&gt;register&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="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;required&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 is required&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;p&gt;That one line completely changed the form.&lt;/p&gt;

&lt;p&gt;If I clicked &lt;strong&gt;Submit&lt;/strong&gt; without entering a name...&lt;/p&gt;

&lt;p&gt;React Hook Form immediately displayed:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Name is required
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And something interesting happened.&lt;/p&gt;

&lt;p&gt;My &lt;code&gt;formSubmit()&lt;/code&gt; function never ran.&lt;/p&gt;

&lt;p&gt;Instead of giving me invalid data...&lt;/p&gt;

&lt;p&gt;React Hook Form stopped everything before submission.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzrbol5q1ogxgd4cfnfiv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fzrbol5q1ogxgd4cfnfiv.png" alt="React Hook Form validation errors"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Validation errors appear before the form is submitted, preventing invalid data from reaching my submit function.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That felt really impressive.&lt;/p&gt;


&lt;h2&gt;
  
  
  📧 Making Sure Emails Actually Look Like Emails
&lt;/h2&gt;

&lt;p&gt;The next field was email.&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="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;email&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;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Email is required&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/^&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;a-zA-Z0-9._%+-&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+@&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;a-zA-Z0-9.-&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;+&lt;/span&gt;&lt;span class="se"&gt;\.[&lt;/span&gt;&lt;span class="sr"&gt;a-zA-Z&lt;/span&gt;&lt;span class="se"&gt;]{2,}&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Please enter valid email&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="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The regular expression looked scary at first. 😅&lt;/p&gt;

&lt;p&gt;I definitely wasn't trying to memorize it.&lt;/p&gt;

&lt;p&gt;What mattered to me was understanding its job.&lt;/p&gt;

&lt;p&gt;If the entered email doesn't match the expected format...&lt;/p&gt;

&lt;p&gt;React Hook Form simply refuses to submit the form and shows my custom error message.&lt;/p&gt;

&lt;p&gt;That made much more sense than manually checking every possible email format myself.&lt;/p&gt;


&lt;h2&gt;
  
  
  📱 Validating a Phone Number
&lt;/h2&gt;

&lt;p&gt;Next came the mobile number.&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="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mobile&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;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Mobile is required&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;minLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Minimum 10 digits are required&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;maxLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Maximum 10 digits are required&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="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This one was interesting.&lt;/p&gt;

&lt;p&gt;Using both &lt;code&gt;minLength&lt;/code&gt; and &lt;code&gt;maxLength&lt;/code&gt; meant the user had to enter exactly &lt;strong&gt;10 digits&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Less than ten?&lt;/p&gt;

&lt;p&gt;Error.&lt;/p&gt;

&lt;p&gt;More than ten?&lt;/p&gt;

&lt;p&gt;Still an error.&lt;/p&gt;

&lt;p&gt;It was a simple way to enforce a rule without writing any custom logic.&lt;/p&gt;


&lt;h2&gt;
  
  
  🖼️ Even the Image Field Needed Validation
&lt;/h2&gt;

&lt;p&gt;The image input looked straightforward.&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="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image&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;required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Image is required&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;p&gt;Without it...&lt;/p&gt;

&lt;p&gt;Someone could submit the form without providing an image.&lt;/p&gt;

&lt;p&gt;The validation rule made sure every user card had all the information it needed before being created.&lt;/p&gt;


&lt;h2&gt;
  
  
  🚨 The &lt;code&gt;errors&lt;/code&gt; Object Did All the Heavy Lifting
&lt;/h2&gt;

&lt;p&gt;One thing I really liked was how React Hook Form keeps track of every validation error.&lt;/p&gt;

&lt;p&gt;Displaying an error was as simple as:&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;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;errors&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="nx"&gt;message&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;p&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;The same pattern worked for every field.&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="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;
&lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mobile&lt;/span&gt;
&lt;span class="nx"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That was much cleaner than writing lots of &lt;code&gt;if&lt;/code&gt; statements myself.&lt;/p&gt;

&lt;p&gt;I didn't need to manually check:&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&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="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;or&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="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt; &lt;span class="o"&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="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;React Hook Form had already done that work for me.&lt;/p&gt;

&lt;p&gt;I only needed to decide how the errors should appear on the screen.&lt;/p&gt;


&lt;h2&gt;
  
  
  📤 Validation Happens Before Submission
&lt;/h2&gt;

&lt;p&gt;One thing finally clicked today.&lt;/p&gt;

&lt;p&gt;I used to think clicking &lt;strong&gt;Submit&lt;/strong&gt; immediately called my function.&lt;/p&gt;

&lt;p&gt;That's not actually what happens.&lt;/p&gt;

&lt;p&gt;The flow looks more like this.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Clicks Submit
          ↓
React Hook Form Checks Every Rule
          ↓
Everything Valid?

YES ✅
Run formSubmit()

NO ❌
Fill the errors Object
Display Error Messages
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That small flow completely changed how I think about forms.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Mental Model
&lt;/h2&gt;

&lt;p&gt;Here's how I visualize today's lesson now.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Types
      ↓
Validation Rules
      ↓
Valid Input?
      ↓
YES ✅ --------→ Submit Form
      ↓
NO ❌ --------→ Show Errors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead of blindly accepting everything...&lt;/p&gt;

&lt;p&gt;The form now protects itself before any data is submitted.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;📝 Building a form is only half the job—validation is just as important.&lt;/li&gt;
&lt;li&gt;🚫 &lt;code&gt;required&lt;/code&gt; prevents empty submissions.&lt;/li&gt;
&lt;li&gt;📧 &lt;code&gt;pattern&lt;/code&gt; helps validate formats like email addresses.&lt;/li&gt;
&lt;li&gt;📱 &lt;code&gt;minLength&lt;/code&gt; and &lt;code&gt;maxLength&lt;/code&gt; can enforce rules such as a 10-digit phone number.&lt;/li&gt;
&lt;li&gt;🚨 React Hook Form automatically stores validation errors inside the &lt;code&gt;errors&lt;/code&gt; object.&lt;/li&gt;
&lt;li&gt;⚡ Validation happens before the submit function is executed.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the React Cohort 3.0 by Devendra Dhote at Sheriyans Coding School.&lt;/p&gt;

&lt;p&gt;This article isn't a copy of the course.&lt;/p&gt;

&lt;p&gt;It's my personal understanding after today's class, rewritten entirely in my own words.&lt;/p&gt;

&lt;p&gt;Writing these articles helps me reinforce what I've learned, and hopefully helps other beginners who are on the same journey. 🤝&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate your corrections in the comments. 😊&lt;/p&gt;


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

&lt;p&gt;Yesterday, I learned how React Hook Form made building forms easier.&lt;/p&gt;

&lt;p&gt;Today, I learned that forms aren't just about collecting data.&lt;/p&gt;

&lt;p&gt;They're also responsible for protecting it.&lt;/p&gt;

&lt;p&gt;That shift completely changed how I look at forms.&lt;/p&gt;

&lt;p&gt;Instead of thinking:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Collect Input
      ↓
Submit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I now think:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Collect Input
      ↓
Validate Input
      ↓
Submit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It seems like a small difference.&lt;/p&gt;

&lt;p&gt;But today's project showed me that validation isn't an extra feature.&lt;/p&gt;

&lt;p&gt;It's part of building a reliable application.&lt;/p&gt;

&lt;p&gt;See you on Day 10! 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;When you first started building forms, did you add validation from the beginning, or did you realize its importance only after seeing users enter unexpected data? I'd love to hear your experience in the comments. 😊&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 8 of Learning React: Why Doesn't React Use the DOM Directly? Understanding useRef() &amp; React Hook Form</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Mon, 13 Jul 2026 17:39:31 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-8-of-learning-react-why-doesnt-react-use-the-dom-directly-understanding-useref-react-2c7i</link>
      <guid>https://dev.to/bismay-exe/day-8-of-learning-react-why-doesnt-react-use-the-dom-directly-understanding-useref-react-2c7i</guid>
      <description>&lt;p&gt;📌 &lt;em&gt;Missed Day 7? I explored why sibling components can't share state directly, how lifting state up works, and why moving state to the parent makes component communication much cleaner. You can **read it here&lt;/em&gt;* and then come back. I'll wait. ☕️*&lt;/p&gt;


&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-7-of-learning-react-how-do-components-share-data-understanding-lifting-state-up-3eek" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 7 of Learning React: How Do Components Share Data? Understanding Lifting State Up&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-4135289" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-7-of-learning-react-how-do-components-share-data-understanding-lifting-state-up-3eek" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 13&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-7-of-learning-react-how-do-components-share-data-understanding-lifting-state-up-3eek" id="article-link-4135289"&gt;
          🚀 Day 7 of Learning React: How Do Components Share Data? Understanding Lifting State Up
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-7-of-learning-react-how-do-components-share-data-understanding-lifting-state-up-3eek" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;3&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-7-of-learning-react-how-do-components-share-data-understanding-lifting-state-up-3eek#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              3&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;For the past few days, React has been doing almost everything for me.&lt;/p&gt;

&lt;p&gt;Rendering components...&lt;/p&gt;

&lt;p&gt;Updating the UI...&lt;/p&gt;

&lt;p&gt;Handling state...&lt;/p&gt;

&lt;p&gt;Managing events...&lt;/p&gt;

&lt;p&gt;I barely had to think about the browser itself.&lt;/p&gt;

&lt;p&gt;Today, that changed.&lt;/p&gt;

&lt;p&gt;I needed something React usually hides from us.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The actual DOM.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That was my introduction to &lt;code&gt;useRef()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;But what surprised me even more was what came after that.&lt;/p&gt;

&lt;p&gt;Once I understood &lt;code&gt;useRef&lt;/code&gt;, learning &lt;strong&gt;React Hook Form&lt;/strong&gt; suddenly made a lot more sense.&lt;/p&gt;

&lt;p&gt;Let's dive in. 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday's big question was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How do multiple components share the same state?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I took away from Day 7:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⬆️ Shared state belongs in the nearest common parent.&lt;/li&gt;
&lt;li&gt;📨 Props can pass both data and functions.&lt;/li&gt;
&lt;li&gt;👨‍👧 Sibling components can't directly access each other's state.&lt;/li&gt;
&lt;li&gt;🧩 React's data always flows from parent to child.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today we're answering a different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;If React has a Virtual DOM... how do we access the real DOM? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🌳 React Doesn't Work Directly with the Browser
&lt;/h2&gt;

&lt;p&gt;One thing I learned today is that React usually protects us from working with the real DOM.&lt;/p&gt;

&lt;p&gt;Normally, when we write React code, we're interacting with React itself.&lt;/p&gt;

&lt;p&gt;Not directly with the browser.&lt;/p&gt;

&lt;p&gt;The flow looks something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;My Code
     ↓
React
     ↓
Virtual DOM
     ↓
Real DOM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That means most of the time, React decides &lt;strong&gt;when&lt;/strong&gt; and &lt;strong&gt;how&lt;/strong&gt; the browser should update.&lt;/p&gt;

&lt;p&gt;We don't touch the DOM ourselves.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎯 What Exactly Is the Real DOM?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Real DOM&lt;/strong&gt; is simply the actual webpage the browser creates.&lt;/p&gt;

&lt;p&gt;Every button...&lt;/p&gt;

&lt;p&gt;Every heading...&lt;/p&gt;

&lt;p&gt;Every input...&lt;/p&gt;

&lt;p&gt;Everything you see on the screen exists inside the browser's Document Object Model (DOM).&lt;/p&gt;

&lt;p&gt;That's also where browser APIs and events live.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Real DOM
├── Document
├── Elements
├── Browser APIs
└── Native Events
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React normally keeps us away from it.&lt;/p&gt;

&lt;p&gt;But sometimes...&lt;/p&gt;

&lt;p&gt;We genuinely need access to it.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎭 React Doesn't Even Give Us Native Events
&lt;/h2&gt;

&lt;p&gt;This part surprised me.&lt;/p&gt;

&lt;p&gt;When we write something like:&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="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="si"&gt;}&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;We're not actually working with the browser's native event directly.&lt;/p&gt;

&lt;p&gt;React wraps browser events into something called &lt;strong&gt;Synthetic Events&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The idea looks something like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Browser Event
        ↓
React Wraps It
        ↓
Synthetic Event
        ↓
Our Event Handler
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That wrapper helps React provide a consistent experience across different browsers.&lt;/p&gt;

&lt;p&gt;Another example of React hiding browser details from us.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎣 So... How Do We Reach the Real DOM?
&lt;/h2&gt;

&lt;p&gt;That's exactly why React provides another Hook.&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;inputRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useRef&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead of storing state...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;useRef()&lt;/code&gt; stores a &lt;strong&gt;reference&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That reference can point to a real DOM element.&lt;/p&gt;

&lt;p&gt;Then we connect it like this.&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="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;inputRef&lt;/span&gt;&lt;span class="si"&gt;}&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;Now React gives us access to that input element whenever we need it.&lt;/p&gt;


&lt;h2&gt;
  
  
  📝 Building a Form with &lt;code&gt;useRef()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Today's first form didn't use controlled inputs.&lt;/p&gt;

&lt;p&gt;Instead, every input stored a reference.&lt;/p&gt;

&lt;p&gt;Something like this:&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="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;element&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;formRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;productName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then, when the form was submitted...&lt;/p&gt;

&lt;p&gt;I could read the values directly.&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;product&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;pName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;formRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;productName&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="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;formRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&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="na"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;formRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;category&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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It actually worked really well.&lt;/p&gt;

&lt;p&gt;Seeing values come directly from the DOM was pretty interesting.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤔 But Something Started Feeling Repetitive...
&lt;/h2&gt;

&lt;p&gt;As I added more inputs...&lt;/p&gt;

&lt;p&gt;I noticed something.&lt;/p&gt;

&lt;p&gt;Every field needed another reference.&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="nx"&gt;formRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;productName&lt;/span&gt;
&lt;span class="nx"&gt;formRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;
&lt;span class="nx"&gt;formRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;category&lt;/span&gt;
&lt;span class="nx"&gt;formRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The larger the form became...&lt;/p&gt;

&lt;p&gt;The more repetitive the code felt.&lt;/p&gt;

&lt;p&gt;And that's when today's second topic entered the picture.&lt;/p&gt;


&lt;h2&gt;
  
  
  🚀 Enter React Hook Form
&lt;/h2&gt;

&lt;p&gt;After writing a form manually...&lt;/p&gt;

&lt;p&gt;I tried building the same thing using &lt;strong&gt;React Hook Form&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The first step was installing the package.&lt;/p&gt;

&lt;p&gt;Then everything started with:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;register&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;handleSubmit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useForm&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;One thing I liked immediately was that I could destructure only the things I actually needed.&lt;/p&gt;


&lt;h2&gt;
  
  
  ✨ &lt;code&gt;register()&lt;/code&gt; Felt Like Magic
&lt;/h2&gt;

&lt;p&gt;Instead of creating references manually...&lt;/p&gt;

&lt;p&gt;Every input simply used &lt;code&gt;register()&lt;/code&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt;
  &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;register&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;productName&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&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;That's it.&lt;/p&gt;

&lt;p&gt;No manual refs.&lt;/p&gt;

&lt;p&gt;No repeated logic.&lt;/p&gt;

&lt;p&gt;Every field automatically became part of the form.&lt;/p&gt;

&lt;p&gt;That looked much cleaner.&lt;/p&gt;


&lt;h2&gt;
  
  
  📤 Submitting the Form Became Simpler Too
&lt;/h2&gt;

&lt;p&gt;Instead of collecting every value manually...&lt;/p&gt;

&lt;p&gt;React Hook Form handed everything to me.&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;formSubmit&lt;/span&gt; &lt;span class="o"&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;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;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nf"&gt;reset&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;The &lt;code&gt;data&lt;/code&gt; object already contained every input value.&lt;/p&gt;

&lt;p&gt;No need to write:&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="nx"&gt;formRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&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="nx"&gt;value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;over and over again.&lt;/p&gt;

&lt;p&gt;That was probably my favorite part.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔄 Comparing the Two Approaches
&lt;/h2&gt;

&lt;p&gt;Here's how I think about them now.&lt;/p&gt;
&lt;h3&gt;
  
  
  Using &lt;code&gt;useRef()&lt;/code&gt;
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create Ref
      ↓
Attach Ref
      ↓
Access .current
      ↓
Read Value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Using React Hook Form
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;register()
      ↓
handleSubmit()
      ↓
Receive Form Data
      ↓
Done ✅
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Both approaches work.&lt;/p&gt;

&lt;p&gt;One simply removes a lot of repetitive work.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Mental Model
&lt;/h2&gt;

&lt;p&gt;Here's how today's lesson connects in my head.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React Hides the DOM
          ↓
Need Direct Access?
          ↓
useRef()
          ↓
Building Bigger Forms?
          ↓
React Hook Form
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That simple flow helped everything click.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🎣 &lt;code&gt;useRef()&lt;/code&gt; lets React keep a reference to a real DOM element.&lt;/li&gt;
&lt;li&gt;🌳 React normally works with the Virtual DOM instead of the Real DOM.&lt;/li&gt;
&lt;li&gt;🎭 React wraps browser events into Synthetic Events.&lt;/li&gt;
&lt;li&gt;📝 Forms built with &lt;code&gt;useRef()&lt;/code&gt; work well but become repetitive as they grow.&lt;/li&gt;
&lt;li&gt;🚀 React Hook Form removes much of that repetitive code.&lt;/li&gt;
&lt;li&gt;📦 &lt;code&gt;register()&lt;/code&gt;, &lt;code&gt;handleSubmit()&lt;/code&gt;, and &lt;code&gt;reset()&lt;/code&gt; make form handling much cleaner.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the React Cohort 3.0 by Devendra Dhote at Sheriyans Coding School.&lt;/p&gt;

&lt;p&gt;This article isn't a copy of the course.&lt;/p&gt;

&lt;p&gt;It's my personal understanding after today's class, rewritten entirely in my own words.&lt;/p&gt;

&lt;p&gt;Writing these articles helps me reinforce what I've learned, and hopefully helps other beginners who are on the same journey. 🤝&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate your corrections in the comments. 😊&lt;/p&gt;


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

&lt;p&gt;Today's class answered a question I hadn't really thought about before.&lt;/p&gt;

&lt;p&gt;React usually keeps us away from the browser.&lt;/p&gt;

&lt;p&gt;Most of the time, that's exactly what we want.&lt;/p&gt;

&lt;p&gt;But sometimes...&lt;/p&gt;

&lt;p&gt;We genuinely need access to the real DOM.&lt;/p&gt;

&lt;p&gt;That's where &lt;code&gt;useRef()&lt;/code&gt; comes in.&lt;/p&gt;

&lt;p&gt;And after using it to build a form manually, I could immediately appreciate why libraries like React Hook Form exist.&lt;/p&gt;

&lt;p&gt;They don't replace React.&lt;/p&gt;

&lt;p&gt;They simply remove a lot of repetitive work while still using React's ideas under the hood.&lt;/p&gt;

&lt;p&gt;I feel like today's lesson wasn't just about learning another Hook.&lt;/p&gt;

&lt;p&gt;It was about understanding where React stops... and where we occasionally need to work a little closer to the browser.&lt;/p&gt;

&lt;p&gt;See you on Day 9! 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;When did &lt;code&gt;useRef()&lt;/code&gt; finally click for you? Was it focusing an input, reading form values, or something completely different? I'd love to hear your experience in the comments. 😊&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="auto" class="m-0"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 7 of Learning React: How Do Components Share Data? Understanding Lifting State Up</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Mon, 13 Jul 2026 16:25:37 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-7-of-learning-react-how-do-components-share-data-understanding-lifting-state-up-3eek</link>
      <guid>https://dev.to/bismay-exe/day-7-of-learning-react-how-do-components-share-data-understanding-lifting-state-up-3eek</guid>
      <description>&lt;p&gt;📌 &lt;em&gt;Missed Day 6? I explored how React renders components, why immutable updates matter, how HMR works behind the scenes, and different approaches to handling forms. You can **read it here&lt;/em&gt;* and then come back. I'll wait. ☕️*&lt;/p&gt;


&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-6-of-learning-react-the-day-reacts-rendering-finally-started-making-sense-hmr-bundlers--1epe" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 6 of Learning React: The Day React's Rendering Finally Started Making Sense (HMR, Bundlers &amp;amp; Form Handling)&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image" width="400" height="400"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-4054175" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt="" width="400" height="400"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-6-of-learning-react-the-day-reacts-rendering-finally-started-making-sense-hmr-bundlers--1epe" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 2&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-6-of-learning-react-the-day-reacts-rendering-finally-started-making-sense-hmr-bundlers--1epe" id="article-link-4054175"&gt;
          🚀 Day 6 of Learning React: The Day React's Rendering Finally Started Making Sense (HMR, Bundlers &amp;amp; Form Handling)
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-6-of-learning-react-the-day-reacts-rendering-finally-started-making-sense-hmr-bundlers--1epe" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;8&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-6-of-learning-react-the-day-reacts-rendering-finally-started-making-sense-hmr-bundlers--1epe#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              1&lt;span class="hidden s:inline"&gt;&amp;nbsp;comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            8 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;Yesterday, I spent most of my time learning how React updates the UI.&lt;/p&gt;

&lt;p&gt;Today, I ran into a completely different problem.&lt;/p&gt;

&lt;p&gt;I had a registration form.&lt;/p&gt;

&lt;p&gt;I also had a list of user cards.&lt;/p&gt;

&lt;p&gt;Whenever someone filled out the form and clicked &lt;strong&gt;Register&lt;/strong&gt;, I wanted a new user card to appear automatically.&lt;/p&gt;

&lt;p&gt;Sounds simple...&lt;/p&gt;

&lt;p&gt;Except there was one problem.&lt;/p&gt;

&lt;p&gt;The form and the user cards lived in &lt;strong&gt;different components&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That's when I learned one of React's most important patterns:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Lifting State Up.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's dive in. 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday's big question was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How does React know when something should be re-rendered?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I took away from Day 6:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🛍️ &lt;code&gt;map()&lt;/code&gt; helps render multiple components from data.&lt;/li&gt;
&lt;li&gt;🔄 React prefers immutable updates.&lt;/li&gt;
&lt;li&gt;📝 Forms become much cleaner when using a single reusable change handler.&lt;/li&gt;
&lt;li&gt;🚫 DRY (Don't Repeat Yourself) makes React code easier to maintain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today we're answering a different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How do two components share the same data? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🏗️ The Project
&lt;/h2&gt;

&lt;p&gt;Today's project looked something like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App
├── Register
└── UserCard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;Register&lt;/code&gt; component collected user information.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;UserCard&lt;/code&gt; component displayed all registered users.&lt;/p&gt;

&lt;p&gt;Pretty straightforward.&lt;/p&gt;

&lt;p&gt;At first, I thought these two components could somehow communicate with each other directly.&lt;/p&gt;

&lt;p&gt;They can't.&lt;/p&gt;

&lt;p&gt;That misunderstanding was the beginning of today's lesson.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤔 The Problem
&lt;/h2&gt;

&lt;p&gt;Inside my &lt;code&gt;Register&lt;/code&gt; component, I already had state.&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setFormData&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="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="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&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="na"&gt;password&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="na"&gt;image&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Submitting the form updated &lt;code&gt;formData&lt;/code&gt; perfectly.&lt;/p&gt;

&lt;p&gt;But another question appeared.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How does &lt;code&gt;UserCard&lt;/code&gt; know a new user was registered?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It doesn't.&lt;/p&gt;

&lt;p&gt;Because &lt;code&gt;UserCard&lt;/code&gt; has absolutely no access to &lt;code&gt;Register&lt;/code&gt;'s state.&lt;/p&gt;

&lt;p&gt;That state belongs only to the &lt;code&gt;Register&lt;/code&gt; component.&lt;/p&gt;


&lt;h2&gt;
  
  
  🚫 Sibling Components Can't Read Each Other's State
&lt;/h2&gt;

&lt;p&gt;This was probably the biggest realization of today's class.&lt;/p&gt;

&lt;p&gt;Both components were children of the same parent.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App
├── Register
└── UserCard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That makes them &lt;strong&gt;siblings&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And sibling components cannot directly access each other's state.&lt;/p&gt;

&lt;p&gt;For a while, I kept thinking there must be some way for one component to "look inside" another.&lt;/p&gt;

&lt;p&gt;There isn't.&lt;/p&gt;

&lt;p&gt;React doesn't work like that.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 The Solution Was Surprisingly Simple
&lt;/h2&gt;

&lt;p&gt;Instead of trying to make the two components communicate...&lt;/p&gt;

&lt;p&gt;I moved the shared state &lt;strong&gt;up&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;From this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Register
└── users state
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;To this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App
├── users state
├── Register
└── UserCard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That small change solved everything.&lt;/p&gt;

&lt;p&gt;And that's exactly why this pattern is called:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Lifting State Up.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We're simply moving shared state to the nearest common parent.&lt;/p&gt;


&lt;h2&gt;
  
  
  📦 The Parent Owns the State
&lt;/h2&gt;

&lt;p&gt;Instead of storing users inside &lt;code&gt;Register&lt;/code&gt;, I stored them inside &lt;code&gt;App&lt;/code&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setUsers&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now &lt;code&gt;App&lt;/code&gt; became the single source of truth.&lt;/p&gt;

&lt;p&gt;Instead of owning the users...&lt;/p&gt;

&lt;p&gt;The child components simply used them.&lt;/p&gt;


&lt;h2&gt;
  
  
  📨 Props Started Making Much More Sense
&lt;/h2&gt;

&lt;p&gt;Once the state lived inside &lt;code&gt;App&lt;/code&gt;, everything connected beautifully.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Register&lt;/code&gt; received the updater function.&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;Register&lt;/span&gt; &lt;span class="na"&gt;setUsers&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;setUsers&lt;/span&gt;&lt;span class="si"&gt;}&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;Whenever someone submitted the form,&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Register&lt;/code&gt; simply called:&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="nf"&gt;setUsers&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It wasn't updating its own state anymore.&lt;/p&gt;

&lt;p&gt;It was asking &lt;strong&gt;App&lt;/strong&gt; to update the shared state.&lt;/p&gt;

&lt;p&gt;That tiny detail completely changed how I think about props.&lt;/p&gt;

&lt;p&gt;They're not just for sending data.&lt;/p&gt;

&lt;p&gt;They can also send functions.&lt;/p&gt;


&lt;h2&gt;
  
  
  🪄 Where Did the New User Card Come From?
&lt;/h2&gt;

&lt;p&gt;This was my favorite part.&lt;/p&gt;

&lt;p&gt;I never manually created a new card.&lt;/p&gt;

&lt;p&gt;Instead, &lt;code&gt;App&lt;/code&gt; rendered the cards like this:&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;users&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;elem&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;UserCard&lt;/span&gt;
      &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;elem&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As soon as &lt;code&gt;users&lt;/code&gt; changed...&lt;/p&gt;

&lt;p&gt;React rendered another &lt;code&gt;UserCard&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;No DOM manipulation.&lt;/p&gt;

&lt;p&gt;No extra logic.&lt;/p&gt;

&lt;p&gt;Just a state update.&lt;/p&gt;

&lt;p&gt;That pattern is becoming more and more familiar every day.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Mental Model
&lt;/h2&gt;

&lt;p&gt;Here's how I visualize today's lesson.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Fills Form
        ↓
Register Calls setUsers()
        ↓
App Updates users State
        ↓
App Re-renders
        ↓
Updated users Passed to UserCard
        ↓
New User Card Appears ✨
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That flow made today's topic click for me.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤝 Why Lift the State?
&lt;/h2&gt;

&lt;p&gt;At first, moving state to another component felt unnecessary.&lt;/p&gt;

&lt;p&gt;But after today's project, it actually made perfect sense.&lt;/p&gt;

&lt;p&gt;Now there is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ One place where the users are stored.&lt;/li&gt;
&lt;li&gt;✅ One source of truth.&lt;/li&gt;
&lt;li&gt;✅ Both components stay synchronized.&lt;/li&gt;
&lt;li&gt;✅ No duplicated state.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of each component trying to manage the same information...&lt;/p&gt;

&lt;p&gt;They simply rely on the parent.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🏗️ Components don't automatically share state.&lt;/li&gt;
&lt;li&gt;👨‍👧 Sibling components can't directly access each other's state.&lt;/li&gt;
&lt;li&gt;⬆️ Shared state should live in the nearest common parent.&lt;/li&gt;
&lt;li&gt;📨 Props can pass both data and functions.&lt;/li&gt;
&lt;li&gt;🔄 Updating the parent's state automatically updates every child that depends on it.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the React Cohort 3.0 by Devendra Dhote at Sheriyans Coding School.&lt;/p&gt;

&lt;p&gt;This article isn't a copy of the course.&lt;/p&gt;

&lt;p&gt;It's my personal understanding after today's class, rewritten entirely in my own words.&lt;/p&gt;

&lt;p&gt;Writing these articles helps me reinforce what I've learned, and hopefully helps other beginners who are on the same journey. 🤝&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate your corrections in the comments. 😊&lt;/p&gt;


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

&lt;p&gt;Today's lesson wasn't about learning another Hook or another React API.&lt;/p&gt;

&lt;p&gt;It was about learning where state actually belongs.&lt;/p&gt;

&lt;p&gt;Earlier, I thought state should always stay inside the component that uses it.&lt;/p&gt;

&lt;p&gt;Now I know that's not always true.&lt;/p&gt;

&lt;p&gt;If multiple components need the same information, the best solution isn't to duplicate the state.&lt;/p&gt;

&lt;p&gt;It's to move that state to their nearest common parent and let React's data flow do the rest.&lt;/p&gt;

&lt;p&gt;That one idea made component communication feel much less mysterious.&lt;/p&gt;

&lt;p&gt;See you on Day 8! 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;When you first learned React, did you also try making sibling components share state directly, or did lifting state up click immediately for you? I'd love to hear your experience in the comments. 😊&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 6 of Learning React: The Day React's Rendering Finally Started Making Sense (HMR, Bundlers &amp; Form Handling)</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Thu, 02 Jul 2026 19:40:07 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-6-of-learning-react-the-day-reacts-rendering-finally-started-making-sense-hmr-bundlers--1epe</link>
      <guid>https://dev.to/bismay-exe/day-6-of-learning-react-the-day-reacts-rendering-finally-started-making-sense-hmr-bundlers--1epe</guid>
      <description>&lt;p&gt;📌 &lt;em&gt;Missed Day 5? I explored React's Automatic Batching, why calling &lt;code&gt;setState(count + 1)&lt;/code&gt; three times only increments once, and how functional updates with &lt;code&gt;prev&lt;/code&gt; solve that problem. You can **read it here&lt;/em&gt;* and then come back. I'll wait. ☕️*&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-5-of-learning-react-understanding-automatic-batching-functional-updates-397k" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 5 of Learning React: Understanding Automatic Batching &amp;amp; Functional Updates&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
      &lt;a href="https://dev.to/bismay-exe/day-5-of-learning-react-understanding-automatic-batching-functional-updates-397k" class="crayons-article__context-note crayons-article__context-note__feed"&gt;&lt;p&gt;Expanded update grouping since React 18&lt;/p&gt;

&lt;/a&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image" width="400" height="400"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-4043972" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt="" width="400" height="400"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-5-of-learning-react-understanding-automatic-batching-functional-updates-397k" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jul 1&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-5-of-learning-react-understanding-automatic-batching-functional-updates-397k" id="article-link-4043972"&gt;
          🚀 Day 5 of Learning React: Understanding Automatic Batching &amp;amp; Functional Updates
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-5-of-learning-react-understanding-automatic-batching-functional-updates-397k" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;13&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-5-of-learning-react-understanding-automatic-batching-functional-updates-397k#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              3&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;Yesterday's lesson answered one question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Why doesn't React update immediately after every &lt;code&gt;setState()&lt;/code&gt; call?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Today's class answered another one:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How does React know what to render?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;At first, today's topics felt completely unrelated.&lt;/p&gt;

&lt;p&gt;Rendering with &lt;code&gt;map()&lt;/code&gt;...&lt;/p&gt;

&lt;p&gt;Deleting product cards...&lt;/p&gt;

&lt;p&gt;Hot Module Replacement...&lt;/p&gt;

&lt;p&gt;Primitive and reference types...&lt;/p&gt;

&lt;p&gt;Mutable and immutable values...&lt;/p&gt;

&lt;p&gt;Form handling...&lt;/p&gt;

&lt;p&gt;It honestly felt like React was throwing random concepts at me.&lt;/p&gt;

&lt;p&gt;But somewhere in the middle of the class, something clicked.&lt;/p&gt;

&lt;p&gt;Every single topic was connected by one idea:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;React doesn't care that your data changed. It cares whether it can detect that something changed.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once I started looking at today's lesson from that perspective, everything began making sense.&lt;/p&gt;

&lt;p&gt;Let's dive in. 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday's big question was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Why doesn't &lt;code&gt;setState()&lt;/code&gt; update immediately?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I took away from Day 5:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚡ React automatically batches multiple state updates.&lt;/li&gt;
&lt;li&gt;📦 State updates are stored in an internal update queue.&lt;/li&gt;
&lt;li&gt;🔄 Functional updates with &lt;code&gt;prev&lt;/code&gt; always receive the latest available state.&lt;/li&gt;
&lt;li&gt;🚀 Multiple &lt;code&gt;setState()&lt;/code&gt; calls don't always mean multiple renders.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today we're answering a different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How does React know what needs to be rendered? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  🛍️ One Component... Twenty Product Cards
&lt;/h2&gt;

&lt;p&gt;Today's project was much more interesting than rendering static JSX.&lt;/p&gt;

&lt;p&gt;Instead of writing the same product card over and over again, I created a reusable &lt;code&gt;ProductsCard&lt;/code&gt; component.&lt;/p&gt;

&lt;p&gt;Then I stored &lt;strong&gt;20 product objects&lt;/strong&gt; inside state.&lt;/p&gt;

&lt;p&gt;Rendering them was surprisingly simple.&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;productsData&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;elem&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="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ProductsCard&lt;/span&gt;
        &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;product&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;elem&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;del&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;deleteProduct&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That single &lt;code&gt;map()&lt;/code&gt; generated every product card on the screen.&lt;/p&gt;

&lt;p&gt;If I had written twenty separate components manually...&lt;/p&gt;

&lt;p&gt;I'd just be repeating the same code.&lt;/p&gt;

&lt;p&gt;This reminded me of a programming principle we learned later in class:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;DRY — Don't Repeat Yourself.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead of repeating UI, React encourages us to build reusable components and let data drive the interface.&lt;/p&gt;

&lt;p&gt;That felt much cleaner.&lt;/p&gt;


&lt;h2&gt;
  
  
  🗑️ Simple Delete Function
&lt;/h2&gt;

&lt;p&gt;Each product card had a Delete button.&lt;/p&gt;

&lt;p&gt;Clicking it removed only that specific product.&lt;/p&gt;

&lt;p&gt;The interesting part wasn't the button.&lt;/p&gt;

&lt;p&gt;It was &lt;em&gt;how&lt;/em&gt; React updated the screen.&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;deleteProduct&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&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;products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;productsData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elem&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;elem&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;setProductsData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;products&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;Notice something?&lt;/p&gt;

&lt;p&gt;I never removed any HTML.&lt;/p&gt;

&lt;p&gt;I never searched for a DOM element.&lt;/p&gt;

&lt;p&gt;I never called &lt;code&gt;remove()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;All I did was create a &lt;strong&gt;new array&lt;/strong&gt; without the deleted product.&lt;/p&gt;

&lt;p&gt;Then I updated the state.&lt;/p&gt;

&lt;p&gt;React compared the new array with the previous one...&lt;/p&gt;

&lt;p&gt;Re-rendered the component...&lt;/p&gt;

&lt;p&gt;And only the missing card disappeared from the UI.&lt;/p&gt;

&lt;p&gt;That was another reminder that in React, we don't usually manipulate the DOM ourselves.&lt;/p&gt;

&lt;p&gt;We change the &lt;strong&gt;state&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;React takes care of the UI.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔥 Saving a File Isn't Magic — It's HMR
&lt;/h2&gt;

&lt;p&gt;One thing I had never really paid attention to was what happens after pressing &lt;strong&gt;Ctrl + S&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The browser updates almost instantly.&lt;/p&gt;

&lt;p&gt;But what's actually happening?&lt;/p&gt;

&lt;p&gt;That's where &lt;strong&gt;Hot Module Replacement (HMR)&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;The moment I save a file, Vite immediately detects that something has changed. I even noticed it printing messages like this in the terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fis9d9omj9zmw2sc0yq5i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fis9d9omj9zmw2sc0yq5i.png" alt="Vite HMR terminal output" width="551" height="75"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Every time I save a file, Vite logs an HMR update in the terminal, showing which modules were updated.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Seeing this made HMR feel much less "magical." Vite is constantly watching the project, and whenever a file changes, it knows exactly which module needs to be updated.&lt;/p&gt;

&lt;p&gt;The process looks something like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Save File
      ↓
Vite Detects the Change
      ↓
Updates the Changed Module
      ↓
Browser Receives the Updated Code
      ↓
UI Updates Instantly ⚡
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead of refreshing the entire application, Vite only replaces the module that changed.&lt;/p&gt;

&lt;p&gt;That's why development feels incredibly fast.&lt;/p&gt;


&lt;h2&gt;
  
  
  📦 Bundlers Are Doing More Than I Thought
&lt;/h2&gt;

&lt;p&gt;HMR also led us to bundlers.&lt;/p&gt;

&lt;p&gt;Whenever our code changes, a bundler helps rebuild the project so the browser can understand it.&lt;/p&gt;

&lt;p&gt;The flow looks like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React Files
      ↓
esbuild Transforms the Code
      ↓
Browser Executes JavaScript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We talked about two bundlers in particular:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚡ &lt;strong&gt;esbuild&lt;/strong&gt; — used during development because it's extremely fast.&lt;/li&gt;
&lt;li&gt;📦 &lt;strong&gt;Rollup&lt;/strong&gt; — used for production builds because it focuses on creating optimized bundles.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I had heard both names before.&lt;/p&gt;

&lt;p&gt;Today I finally understood where they fit into the development process.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;During development, Vite mainly relies on esbuild because it's extremely fast.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When creating a production build, Vite uses Rollup to generate optimized bundles.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  🎣 Looking at &lt;code&gt;useState()&lt;/code&gt; From a Different Perspective
&lt;/h2&gt;

&lt;p&gt;We've spent the last couple of days working with &lt;code&gt;useState()&lt;/code&gt;, but today we summarized what it actually does.&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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This tiny Hook is responsible for several important things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🧠 Maintaining state.&lt;/li&gt;
&lt;li&gt;✏️ Updating state.&lt;/li&gt;
&lt;li&gt;🔄 Re-rendering its component.&lt;/li&gt;
&lt;li&gt;⚡ Making the UI interactive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It may look simple...&lt;/p&gt;

&lt;p&gt;But it's doing a lot behind the scenes.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤯 The Object Experiment That Completely Confused Me
&lt;/h2&gt;

&lt;p&gt;Numbers behaved exactly how I expected.&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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then I tried storing an object.&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="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;setUser&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="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;New User&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;p&gt;I expected updating the object to work exactly like updating a number.&lt;/p&gt;

&lt;p&gt;It didn't.&lt;/p&gt;

&lt;p&gt;That confused me.&lt;/p&gt;

&lt;p&gt;The solution turned out to be surprisingly simple.&lt;/p&gt;

&lt;p&gt;Instead of changing the existing object...&lt;/p&gt;

&lt;p&gt;I created a &lt;strong&gt;new object&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Suddenly everything worked.&lt;/p&gt;

&lt;p&gt;That tiny change introduced me to one of the most important ideas in React.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧩 Primitive vs Reference Types
&lt;/h2&gt;

&lt;p&gt;To understand why the object behaved differently, we first talked about JavaScript values.&lt;/p&gt;

&lt;p&gt;Primitive values include things like:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Number
String
Boolean
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Reference values include:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Object
Array
Function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The biggest difference is that primitive values store the actual value.&lt;/p&gt;

&lt;p&gt;Reference types store a reference to where that value lives in memory.&lt;/p&gt;

&lt;p&gt;That difference becomes really important when React decides whether something has changed.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔄 Mutable vs Immutable — The Example That Made It Click
&lt;/h2&gt;

&lt;p&gt;This was probably my favorite explanation from today's class.&lt;/p&gt;

&lt;p&gt;Imagine you have a notebook.&lt;/p&gt;
&lt;h3&gt;
  
  
  📝 Mutable
&lt;/h3&gt;

&lt;p&gt;You erase what's written on page one.&lt;/p&gt;

&lt;p&gt;Then you write something new on &lt;strong&gt;that same page&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The notebook is still the same notebook.&lt;/p&gt;

&lt;p&gt;Only its contents changed.&lt;/p&gt;

&lt;p&gt;Objects and arrays behave like this.&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="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Alex&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;The object is still the same object.&lt;/p&gt;

&lt;p&gt;Only one property changed.&lt;/p&gt;


&lt;h3&gt;
  
  
  📄 Immutable
&lt;/h3&gt;

&lt;p&gt;Now imagine making a photocopy of that notebook first.&lt;/p&gt;

&lt;p&gt;You leave the original untouched.&lt;/p&gt;

&lt;p&gt;Then you edit the copied version.&lt;/p&gt;

&lt;p&gt;That's what immutable updates look like.&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;updatedUser&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="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;Alex&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;p&gt;Instead of changing the original object...&lt;/p&gt;

&lt;p&gt;We create a brand new one.&lt;/p&gt;

&lt;p&gt;React can easily detect that the reference has changed when you create a &lt;strong&gt;new object&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you mutate the existing object, the reference stays the same, making it harder for React to know something changed.&lt;/p&gt;

&lt;p&gt;That finally explained why creating a new object fixed my state update.&lt;/p&gt;


&lt;h2&gt;
  
  
  📝 One Form, Three Different Approaches
&lt;/h2&gt;

&lt;p&gt;The last topic I explored today was &lt;strong&gt;form handling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;More specifically...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input handling.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What I found interesting wasn't the form itself.&lt;/p&gt;

&lt;p&gt;It was how the solution became cleaner with every new approach.&lt;/p&gt;

&lt;p&gt;The goal never changed.&lt;/p&gt;

&lt;p&gt;Collect the user's input.&lt;/p&gt;

&lt;p&gt;Only the implementation did.&lt;/p&gt;


&lt;h3&gt;
  
  
  1️⃣ Brute Force
&lt;/h3&gt;

&lt;p&gt;The first approach was the most straightforward.&lt;/p&gt;

&lt;p&gt;Every input had its own state.&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="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="nx"&gt;setName&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;email&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setEmail&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;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPassword&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Each input also had its own &lt;code&gt;onChange&lt;/code&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nf"&gt;setName&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="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="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nf"&gt;setEmail&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="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="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nf"&gt;setPassword&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="si"&gt;}&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;There's nothing wrong with this approach.&lt;/p&gt;

&lt;p&gt;But after looking at it for a minute, the repetition becomes obvious.&lt;/p&gt;

&lt;p&gt;Every new input means another state...&lt;/p&gt;

&lt;p&gt;Another &lt;code&gt;onChange&lt;/code&gt;...&lt;/p&gt;

&lt;p&gt;And another piece of nearly identical code.&lt;/p&gt;


&lt;h3&gt;
  
  
  2️⃣ Better Approach
&lt;/h3&gt;

&lt;p&gt;The next version reduced that repetition by storing everything inside a single object.&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setFormData&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="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="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;email&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="na"&gt;password&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Updating an input looked like this:&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="nt"&gt;input&lt;/span&gt;
  &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="nf"&gt;setFormData&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;email&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="p"&gt;})&lt;/span&gt;
  &lt;span class="si"&gt;}&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;One state object was enough to store every field.&lt;/p&gt;

&lt;p&gt;Definitely cleaner.&lt;/p&gt;

&lt;p&gt;But every input still repeated almost the same &lt;code&gt;onChange&lt;/code&gt; logic.&lt;/p&gt;

&lt;p&gt;Only the property name changed.&lt;/p&gt;


&lt;h3&gt;
  
  
  3️⃣ Optimized Approach
&lt;/h3&gt;

&lt;p&gt;The final version was easily my favorite.&lt;/p&gt;

&lt;p&gt;Instead of creating separate handlers...&lt;/p&gt;

&lt;p&gt;One function handled every input.&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;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="kd"&gt;const&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="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&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="nf"&gt;setFormData&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;,&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="nx"&gt;value&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;Now every input looked almost identical.&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="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"name"&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleChange&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="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"email"&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleChange&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="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt; &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleChange&lt;/span&gt;&lt;span class="si"&gt;}&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;The clever part was this line:&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;name&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If the input's &lt;code&gt;name&lt;/code&gt; is &lt;code&gt;"email"&lt;/code&gt;...&lt;/p&gt;

&lt;p&gt;React updates:&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="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;email&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If the input's &lt;code&gt;name&lt;/code&gt; is &lt;code&gt;"password"&lt;/code&gt;...&lt;/p&gt;

&lt;p&gt;React updates:&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="nx"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The same function works for every field.&lt;/p&gt;

&lt;p&gt;No extra handlers.&lt;/p&gt;

&lt;p&gt;No repeated logic.&lt;/p&gt;

&lt;p&gt;Just one reusable solution.&lt;/p&gt;

&lt;p&gt;That immediately reminded me of another principle from today's class:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;DRY — Don't Repeat Yourself.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The optimized version wasn't just shorter.&lt;/p&gt;

&lt;p&gt;It was much easier to maintain, especially as the number of inputs grows.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 DRY — Don't Repeat Yourself
&lt;/h2&gt;

&lt;p&gt;Today's optimized form perfectly demonstrated one principle:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;DRY — Don't Repeat Yourself.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I noticed React encourages this idea everywhere.&lt;/p&gt;

&lt;p&gt;Instead of writing twenty product cards...&lt;/p&gt;

&lt;p&gt;We use &lt;code&gt;map()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Instead of writing three different change handlers...&lt;/p&gt;

&lt;p&gt;We use one reusable function.&lt;/p&gt;

&lt;p&gt;Instead of building separate components that look almost identical...&lt;/p&gt;

&lt;p&gt;We reuse the same component with different props.&lt;/p&gt;

&lt;p&gt;The more I work with React, the more I realize it's constantly pushing me toward writing cleaner, reusable code.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Mental Model
&lt;/h2&gt;

&lt;p&gt;Here's how I connect today's topics in my head:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;State Update
      ↓
React Compares the Previous State
      ↓
If Something Changed
      ↓
Component Re-renders
      ↓
Updated UI ✨
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Whether it's deleting a product...&lt;/p&gt;

&lt;p&gt;Updating an object...&lt;/p&gt;

&lt;p&gt;Or typing inside a form...&lt;/p&gt;

&lt;p&gt;The same rendering process keeps happening behind the scenes.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🛍️ &lt;code&gt;map()&lt;/code&gt; lets us render large amounts of UI without repeating code.&lt;/li&gt;
&lt;li&gt;🗑️ Updating state is enough for React to update the UI—we rarely touch the DOM directly.&lt;/li&gt;
&lt;li&gt;🔥 HMR instantly updates changed modules, making development much faster.&lt;/li&gt;
&lt;li&gt;📦 esbuild powers development, while Rollup creates optimized production builds.&lt;/li&gt;
&lt;li&gt;🧩 Objects and arrays are reference types, while numbers, strings, and booleans are primitive values.&lt;/li&gt;
&lt;li&gt;🔄 React prefers immutable updates because creating new objects and arrays makes changes easier to detect.&lt;/li&gt;
&lt;li&gt;📝 Form handling becomes much cleaner when one reusable function manages every input.&lt;/li&gt;
&lt;li&gt;🚫 DRY (Don't Repeat Yourself) is a principle that shows up everywhere in React.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the React Cohort 3.0 by Devendra Dhote at Sheriyans Coding School.&lt;/p&gt;

&lt;p&gt;This article isn't a copy of the course.&lt;/p&gt;

&lt;p&gt;It's my personal understanding after today's class, rewritten entirely in my own words.&lt;/p&gt;

&lt;p&gt;Writing these articles helps me reinforce what I've learned, and hopefully helps other beginners who are on the same journey. 🤝&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate your corrections in the comments. 😊&lt;/p&gt;


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

&lt;p&gt;Today's class looked overwhelming at first because it covered so many different topics.&lt;/p&gt;

&lt;p&gt;But after connecting all the dots, I realized they all revolve around the same idea.&lt;/p&gt;

&lt;p&gt;React needs a reliable way to know when something has changed.&lt;/p&gt;

&lt;p&gt;Whether it's rendering a list with &lt;code&gt;map()&lt;/code&gt;, deleting an item by updating state, creating a new object instead of mutating an old one, or building reusable form handlers, everything ultimately comes back to helping React render efficiently.&lt;/p&gt;

&lt;p&gt;The more I learn React, the more I realize that most concepts eventually come back to one question:&lt;/p&gt;

&lt;p&gt;How can React reliably detect that something has changed?&lt;/p&gt;

&lt;p&gt;Today's class made that question much easier to answer.&lt;/p&gt;

&lt;p&gt;See you on Day 7! 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;Which concept took you the longest to understand when learning React—rendering, immutability, or form handling? I'd love to hear what finally made it click for you. 😊&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 5 of Learning React: Understanding Automatic Batching &amp; Functional Updates</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Wed, 01 Jul 2026 17:57:22 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-5-of-learning-react-understanding-automatic-batching-functional-updates-397k</link>
      <guid>https://dev.to/bismay-exe/day-5-of-learning-react-understanding-automatic-batching-functional-updates-397k</guid>
      <description>&lt;p&gt;📌 &lt;em&gt;Missed Day 4? I explored what React Hooks are, why &lt;code&gt;useState()&lt;/code&gt; returns two values, how React remembers state, and why calling the setter function triggers a re-render. You can &lt;a href="https://dev.to/bismay-exe/day-4-of-learning-react-what-actually-makes-react-react-hooks-usestate-and-state-198g"&gt;&lt;strong&gt;read it here&lt;/strong&gt;&lt;/a&gt; and then come back. I'll wait. ☕️&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-4-of-learning-react-what-actually-makes-react-react-hooks-usestate-and-state-198g" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 4 of Learning React: What Actually Makes React... React? (Hooks, useState, and State Explained)&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image" width="400" height="400"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-3991386" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt="" width="400" height="400"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-4-of-learning-react-what-actually-makes-react-react-hooks-usestate-and-state-198g" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jun 25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-4-of-learning-react-what-actually-makes-react-react-hooks-usestate-and-state-198g" id="article-link-3991386"&gt;
          🚀 Day 4 of Learning React: What Actually Makes React... React? (Hooks, useState, and State Explained)
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javasc"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javasc&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-4-of-learning-react-what-actually-makes-react-react-hooks-usestate-and-state-198g" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;11&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-4-of-learning-react-what-actually-makes-react-react-hooks-usestate-and-state-198g#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              2&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;Yesterday, I learned that calling &lt;code&gt;setState()&lt;/code&gt; tells React to update the UI.&lt;/p&gt;

&lt;p&gt;So naturally, I assumed something like this:&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="nf"&gt;setCount&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="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;setAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;would make React render...&lt;/p&gt;

&lt;p&gt;Three times.&lt;/p&gt;

&lt;p&gt;Turns out, I was completely wrong.&lt;/p&gt;

&lt;p&gt;Today I learned that React is much smarter than that.&lt;/p&gt;

&lt;p&gt;Instead of rendering after every state update, React &lt;strong&gt;groups multiple updates together&lt;/strong&gt; and performs only &lt;strong&gt;one render&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This optimization is called &lt;strong&gt;Automatic Batching&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And honestly...&lt;/p&gt;

&lt;p&gt;Once I understood batching, a lot of React's behavior finally started making sense.&lt;/p&gt;

&lt;p&gt;Let's dive in. 🚀&lt;/p&gt;


&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday's big question was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How does React know when to update the UI?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I learned on Day 4:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🎣 Hooks give React components memory.&lt;/li&gt;
&lt;li&gt;⚡ &lt;code&gt;useState()&lt;/code&gt; returns the current state and a setter function.&lt;/li&gt;
&lt;li&gt;🔄 Calling the setter updates the state and triggers a re-render.&lt;/li&gt;
&lt;li&gt;🧠 React skips updates when the new state is the same as the old one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today we're answering a different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What happens when we call &lt;code&gt;setState()&lt;/code&gt; multiple times? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  ⚡ React Doesn't Render After Every &lt;code&gt;setState()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Suppose we write:&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="nf"&gt;setCount&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="nf"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Dev&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;setAge&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;My first thought was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"React must be rendering three separate times."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Nope.&lt;/p&gt;

&lt;p&gt;React groups all of those state updates together before rendering.&lt;/p&gt;

&lt;p&gt;The flow looks something like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Multiple State Updates
        ↓
React Batches Them
        ↓
Single Render
        ↓
Single Commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead of doing unnecessary work, React waits, collects all the updates, and applies them together.&lt;/p&gt;

&lt;p&gt;That's what &lt;strong&gt;Automatic Batching&lt;/strong&gt; is all about.&lt;/p&gt;

&lt;p&gt;It's one of React's built-in optimizations that helps improve performance.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤯 The Counter Experiment That Confused Me
&lt;/h2&gt;

&lt;p&gt;After learning about batching, I tried something interesting.&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="nt"&gt;button&lt;/span&gt;
  &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="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;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="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  Increase
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&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;I expected the counter to jump like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 → 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead...&lt;/p&gt;

&lt;p&gt;It became:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0 → 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Wait...&lt;/p&gt;

&lt;p&gt;I called &lt;code&gt;setCount()&lt;/code&gt; three times.&lt;/p&gt;

&lt;p&gt;Why did it only increase once?&lt;/p&gt;


&lt;h2&gt;
  
  
  🧩 What React Actually Sees
&lt;/h2&gt;

&lt;p&gt;At first, it looked like I was asking React to increase the counter three times.&lt;/p&gt;

&lt;p&gt;But that's not what's really happening.&lt;/p&gt;

&lt;p&gt;Assume the current value of &lt;code&gt;count&lt;/code&gt; is:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Every line becomes:&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="nf"&gt;setCount&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="nf"&gt;setCount&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="nf"&gt;setCount&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React batches those updates together.&lt;/p&gt;

&lt;p&gt;Since every update is trying to set the state to the &lt;strong&gt;same value&lt;/strong&gt;, the final result is simply:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That's why the counter only increases once.&lt;/p&gt;

&lt;p&gt;This was a really interesting moment because it showed me that &lt;code&gt;setCount(count + 1)&lt;/code&gt; isn't saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Increase the count."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's actually saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Set the count to this calculated value."&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  🔄 The Mysterious &lt;code&gt;prev&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Then our instructor introduced something new:&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;At first, I wondered...&lt;/p&gt;

&lt;p&gt;What exactly is &lt;code&gt;prev&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;The simplest way I understand it now is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;prev&lt;/code&gt; is the latest state React has available while processing the update queue.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's basically the current state at that particular moment.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤯 My Biggest "Wait... What?" Moment
&lt;/h2&gt;

&lt;p&gt;I accidentally wrote this:&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;When I clicked the button...&lt;/p&gt;

&lt;p&gt;The counter became:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;🤯&lt;/p&gt;

&lt;p&gt;For a second, I thought React was broken.&lt;/p&gt;

&lt;p&gt;Turns out...&lt;/p&gt;

&lt;p&gt;The problem was mine.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 Why Did It Become &lt;code&gt;undefined&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Arrow functions with curly braces don't automatically return a value.&lt;/p&gt;

&lt;p&gt;I forgot to write:&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;prev&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;So React received:&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="kc"&gt;undefined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;instead of a number.&lt;/p&gt;

&lt;p&gt;The correct version is:&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Or, even shorter:&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That tiny &lt;code&gt;return&lt;/code&gt; completely changed the result.&lt;/p&gt;


&lt;h2&gt;
  
  
  🚀 Why Functional Updates Work
&lt;/h2&gt;

&lt;p&gt;Now let's use the functional version three times.&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="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&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;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&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;setCount&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prev&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;prev&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This time, the counter actually increases by &lt;strong&gt;3&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because React doesn't keep using the original value.&lt;/p&gt;

&lt;p&gt;Instead, each updater receives the latest available state.&lt;/p&gt;

&lt;p&gt;The process looks like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Initial State
count = 0
    │
    ▼
First updater
prev = 0
returns 1
    │
    ▼
count = 1
    │
    ▼
Second updater
prev = 1
returns 2
    │
    ▼
count = 2
    │
    ▼
Third updater
prev = 2
returns 3
    │
    ▼
Final State
count = 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That was probably my favorite part of today's lesson.&lt;/p&gt;

&lt;p&gt;I finally understood why React recommends &lt;strong&gt;functional updates&lt;/strong&gt; whenever the next state depends on the previous one.&lt;/p&gt;


&lt;h2&gt;
  
  
  📦 React's Update Queue
&lt;/h2&gt;

&lt;p&gt;Another thing I learned today is that React doesn't execute state updates immediately.&lt;/p&gt;

&lt;p&gt;Instead, it stores them in something called an &lt;strong&gt;Update Queue&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Imagine writing:&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="nf"&gt;setCount&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="nf"&gt;setCount&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="nf"&gt;setCount&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React doesn't instantly update the UI after each line.&lt;/p&gt;

&lt;p&gt;The flow is more like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setState()
      ↓
Update Queue
      ↓
React Processes Updates
      ↓
Render
      ↓
Commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This update queue is what makes features like batching and functional updates possible.&lt;/p&gt;

&lt;p&gt;React collects everything first...&lt;/p&gt;

&lt;p&gt;Then processes it efficiently.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Mental Model
&lt;/h2&gt;

&lt;p&gt;Here's how I visualize today's lesson:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Multiple setState() Calls
          ↓
Stored Inside React's Update Queue
          ↓
React Batches Them Together
          ↓
Processes Every Update
          ↓
Renders Once
          ↓
Browser Shows Updated UI ✨
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That flow made today's topic much easier to understand.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;⚡ React automatically batches multiple state updates together.&lt;/li&gt;
&lt;li&gt;🎯 Multiple &lt;code&gt;setState()&lt;/code&gt; calls don't always mean multiple renders.&lt;/li&gt;
&lt;li&gt;🧠 &lt;code&gt;setCount(count + 1)&lt;/code&gt; uses the value from the current render, which is why calling it multiple times doesn't keep increasing the count.&lt;/li&gt;
&lt;li&gt;🔄 Functional updates receive the latest available state through &lt;code&gt;prev&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;📦 React processes state updates through an internal update queue before rendering.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the React Cohort 3.0 by Devendra Dhote at Sheriyans Coding School.&lt;/p&gt;

&lt;p&gt;This article isn't a copy of the course.&lt;/p&gt;

&lt;p&gt;It's my personal understanding after today's class, rewritten entirely in my own words.&lt;/p&gt;

&lt;p&gt;Writing these articles helps me reinforce what I've learned, and hopefully helps other beginners who are on the same journey. 🤝&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate your corrections in the comments. 😊&lt;/p&gt;


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

&lt;p&gt;Before today's class, I thought every call to &lt;code&gt;setState()&lt;/code&gt; immediately changed the state and re-rendered the component.&lt;/p&gt;

&lt;p&gt;Now I know that's not how React works.&lt;/p&gt;

&lt;p&gt;React first &lt;strong&gt;collects&lt;/strong&gt; state updates, &lt;strong&gt;batches&lt;/strong&gt; them together, and then processes them efficiently.&lt;/p&gt;

&lt;p&gt;The biggest surprise for me wasn't batching itself.&lt;/p&gt;

&lt;p&gt;It was realizing why the functional update form exists.&lt;/p&gt;

&lt;p&gt;I used to think &lt;code&gt;prev&lt;/code&gt; was just another parameter.&lt;/p&gt;

&lt;p&gt;Now I understand it's React's way of giving each update the latest available state while processing the update queue.&lt;/p&gt;

&lt;p&gt;That small detail completely changed how I think about multiple state updates.&lt;/p&gt;

&lt;p&gt;Tomorrow's topic is &lt;strong&gt;State Lifting&lt;/strong&gt;, and after today's lesson, I'm curious to see how different components can share the same state.&lt;/p&gt;

&lt;p&gt;See you on Day 6! 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;What confused you the most when you first learned React's batching behavior? Were you surprised that calling &lt;code&gt;setState(count + 1)&lt;/code&gt; three times only updates the counter once, or did functional updates with &lt;code&gt;prev&lt;/code&gt; take longer to click?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 4 of Learning React: What Actually Makes React... React? (Hooks, useState, and State Explained)</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Thu, 25 Jun 2026 18:03:57 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-4-of-learning-react-what-actually-makes-react-react-hooks-usestate-and-state-198g</link>
      <guid>https://dev.to/bismay-exe/day-4-of-learning-react-what-actually-makes-react-react-hooks-usestate-and-state-198g</guid>
      <description>&lt;p&gt;📌 &lt;em&gt;Missed Day 3? I covered what actually happens after running &lt;code&gt;npm run dev&lt;/code&gt;, how bundlers work, JSX, components, and props. You can &lt;a href="https://dev.to/bismay-exe/react-learning-journey-day-3-understanding-jsx-components-props-bundlers-and-what-happens-56i8"&gt;&lt;strong&gt;read it here&lt;/strong&gt;&lt;/a&gt; and then come back. I'll wait. ☕️&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/react-learning-journey-day-3-understanding-jsx-components-props-bundlers-and-what-happens-56i8" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 3 of Learning React: Understanding JSX, Components, Props, Bundlers, and What Happens After `npm run dev`&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image" width="400" height="400"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-3982670" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt="" width="400" height="400"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/react-learning-journey-day-3-understanding-jsx-components-props-bundlers-and-what-happens-56i8" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jun 24&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/react-learning-journey-day-3-understanding-jsx-components-props-bundlers-and-what-happens-56i8" id="article-link-3982670"&gt;
          🚀 Day 3 of Learning React: Understanding JSX, Components, Props, Bundlers, and What Happens After `npm run dev`
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/react-learning-journey-day-3-understanding-jsx-components-props-bundlers-and-what-happens-56i8" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;13&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/react-learning-journey-day-3-understanding-jsx-components-props-bundlers-and-what-happens-56i8#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              4&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            6 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;If someone asked me yesterday what makes React different from plain JavaScript, I probably would've talked about JSX or components.&lt;/p&gt;

&lt;p&gt;Today, I'd give a completely different answer.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Hooks.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Until today, I thought Hooks were just another React feature.&lt;/p&gt;

&lt;p&gt;Turns out, they're much more than that.&lt;/p&gt;

&lt;p&gt;Hooks are special functions that let React components &lt;strong&gt;remember information between renders&lt;/strong&gt;. Without them, every time a component ran, it would start from scratch with no memory of what happened before.&lt;/p&gt;

&lt;p&gt;The simplest way I can describe them after today's class is this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Hooks are what actually make React... react.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's dive in. 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday we answered one question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What actually happens after we run &lt;code&gt;npm run dev&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I took away from Day 3:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚙️ &lt;code&gt;npm run dev&lt;/code&gt; starts a development server.&lt;/li&gt;
&lt;li&gt;📦 A bundler processes and optimizes our files.&lt;/li&gt;
&lt;li&gt;✨ JSX gets transformed into JavaScript.&lt;/li&gt;
&lt;li&gt;🧩 Components help us build reusable UI.&lt;/li&gt;
&lt;li&gt;📨 Props let components communicate.&lt;/li&gt;
&lt;li&gt;🌳 React finally updates the DOM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today we're answering a different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How does React know when to update the UI? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's where Hooks come in.&lt;/p&gt;




&lt;h2&gt;
  
  
  📦 Import &amp;amp; Export — Something I Thought I Already Knew
&lt;/h2&gt;

&lt;p&gt;Example:&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="c1"&gt;// Button.jsx&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;Button&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click Me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&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;When you import it in another file, the name you give the import does not have to match the name defined in Button.jsx:&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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MyButton&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;./Button&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;h3&gt;
  
  
  Why the name doesn't matter
&lt;/h3&gt;

&lt;p&gt;When you use a default export, you are essentially telling the module: &lt;em&gt;"Give me whatever is exported as default, and I will call it 'MyButton' in this file."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Behind the scenes, the module system only cares about the &lt;strong&gt;file path&lt;/strong&gt; ("./Button"). Since there can only be one default export per file, the environment knows exactly which piece of code to grab, regardless of what you name it locally.&lt;/p&gt;

&lt;p&gt;This is different from &lt;strong&gt;named exports&lt;/strong&gt;, where you must use the exact name defined in the curly braces—for example: import { Button } from "./Button";.&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Button&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Card&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 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;Button&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Card&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;./components&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;Why braces are required?&lt;/p&gt;

&lt;p&gt;Because internally, named exports are stored by their exported names, while the default export is stored under a special &lt;code&gt;"default"&lt;/code&gt; binding.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎣 My First Hook — &lt;code&gt;useState()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Today's biggest highlight was finally learning my &lt;strong&gt;first React Hook&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That hook is:&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="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="nx"&gt;initialValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;At first glance, this syntax looked... strange. 😅&lt;/p&gt;

&lt;p&gt;Why is it returning an array?&lt;/p&gt;

&lt;p&gt;Why are there two variables?&lt;/p&gt;

&lt;p&gt;And what exactly are &lt;code&gt;state&lt;/code&gt; and &lt;code&gt;setState&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Once I understood what each one does, everything started making sense.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧩 &lt;code&gt;useState()&lt;/code&gt; Returns Two Things
&lt;/h2&gt;

&lt;p&gt;One thing I learned today is that &lt;code&gt;useState()&lt;/code&gt; doesn't return a single value.&lt;/p&gt;

&lt;p&gt;It returns &lt;strong&gt;an array with exactly two elements&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="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="nx"&gt;initialValue&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Conceptually, React is giving us something like this:&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="p"&gt;[&lt;/span&gt;
  &lt;span class="nx"&gt;currentState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;updateStateFunction&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Using array destructuring, we store those values into two variables:&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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;count&lt;/code&gt; stores the current state value.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;setCount&lt;/code&gt; is the function React gives us to update that value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I finally understood why there are two variables instead of one.&lt;/p&gt;

&lt;p&gt;One is &lt;strong&gt;the data&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The other is &lt;strong&gt;the way to change the data.&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  🟢 What Exactly Is &lt;code&gt;state&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;The first value returned by &lt;code&gt;useState()&lt;/code&gt; is the &lt;strong&gt;state itself&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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here:&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="nx"&gt;count&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;is simply the current value React is remembering.&lt;/p&gt;

&lt;p&gt;If the value changes from:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;to&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;then &lt;code&gt;count&lt;/code&gt; will become &lt;code&gt;1&lt;/code&gt; on the next render.&lt;/p&gt;

&lt;p&gt;I like thinking of state as React's memory.&lt;/p&gt;

&lt;p&gt;Unlike normal variables, &lt;strong&gt;state survives between renders.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's what makes it special.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔄 What Does &lt;code&gt;setState&lt;/code&gt; Actually Do?
&lt;/h2&gt;

&lt;p&gt;This was probably the biggest "aha!" moment for me today.&lt;/p&gt;

&lt;p&gt;I originally thought &lt;code&gt;setState&lt;/code&gt; only changed a variable.&lt;/p&gt;

&lt;p&gt;Turns out, it does &lt;strong&gt;two very important things.&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="nf"&gt;setCount&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  1️⃣ It Updates the State
&lt;/h3&gt;

&lt;p&gt;First, React stores the new value internally.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;count = 0

↓

setCount(1)

↓

count = 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Pretty straightforward.&lt;/p&gt;

&lt;p&gt;But that's only half the story.&lt;/p&gt;
&lt;h3&gt;
  
  
  2️⃣ It Triggers a Re-render
&lt;/h3&gt;

&lt;p&gt;This is the part I didn't know before today.&lt;/p&gt;

&lt;p&gt;Calling &lt;code&gt;setState()&lt;/code&gt; doesn't just update the value.&lt;/p&gt;

&lt;p&gt;It also tells React:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"Something changed. Run this component again."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That means React calls the component function one more time with the updated state and generates a new UI.&lt;/p&gt;

&lt;p&gt;That's why the screen updates automatically.&lt;/p&gt;

&lt;p&gt;Without &lt;code&gt;setState()&lt;/code&gt;, React wouldn't know anything changed.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Mental Model
&lt;/h2&gt;

&lt;p&gt;Here's how I visualize it now:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Clicks Button
        ↓
setState(newValue)
        ↓
React Updates State
        ↓
React Re-renders Component
        ↓
New UI is Generated
        ↓
Browser Shows Updated UI ✨
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;That simple flow made &lt;code&gt;useState()&lt;/code&gt; click for me.&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;function&lt;/span&gt; &lt;span class="nf"&gt;Counter&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="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&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;h2&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="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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="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="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Increase
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&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;h3&gt;
  
  
  🔵 &lt;code&gt;setCount&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;This does two important things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Updates the state.&lt;/li&gt;
&lt;li&gt;Tells React to render the component again.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That second point surprised me the most.&lt;/p&gt;

&lt;p&gt;I used to think it only changed a variable.&lt;/p&gt;

&lt;p&gt;It actually tells React:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Hey... something changed. Build the UI again."&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  🤯 The Boolean Experiment That Confused Me
&lt;/h2&gt;

&lt;p&gt;This will be the most interesting section because it's my own discovery.&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;flag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setFlag&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then tell the story.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I expected every button click to re-render.&lt;/p&gt;

&lt;p&gt;But that's not what happened.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then explain&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="nf"&gt;setFlag&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;p&gt;No update.&lt;/p&gt;

&lt;p&gt;Because...&lt;/p&gt;

&lt;p&gt;React already has &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Nothing changed.&lt;/p&gt;

&lt;p&gt;So React skips everything.&lt;/p&gt;



&lt;p&gt;Then&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="nf"&gt;setFlag&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;First click&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;true → false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React updates.&lt;/p&gt;

&lt;p&gt;Second click&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;false → false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Nothing changed.&lt;/p&gt;

&lt;p&gt;React ignores it.&lt;/p&gt;

&lt;p&gt;That was a really cool moment because it showed me React isn't blindly rendering every time.&lt;/p&gt;

&lt;p&gt;It first checks whether the new state is actually different.&lt;/p&gt;


&lt;h2&gt;
  
  
  📜 A Rule I Learned Today
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;setState(newValue)

↓

Is newValue different?

↓

YES ✅
Update state
Render component

NO ❌
Skip update
Skip render
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  💡 My Biggest Takeaways Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;📦 I finally understand the difference between default and named exports.&lt;/li&gt;
&lt;li&gt;🎣 Hooks are what give React components memory.&lt;/li&gt;
&lt;li&gt;⚡ &lt;code&gt;useState()&lt;/code&gt; returns the current state and a setter function.&lt;/li&gt;
&lt;li&gt;🔄 Calling the setter tells React to render again—but only if the value actually changes.&lt;/li&gt;
&lt;li&gt;🧠 React avoids unnecessary renders by comparing the old and new state.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the React Cohort 3.0 by Devendra Dhote at Sheriyans Coding School.&lt;/p&gt;

&lt;p&gt;This article isn't a copy of the course.&lt;/p&gt;

&lt;p&gt;It's my personal understanding after today's class, rewritten entirely in my own words.&lt;/p&gt;

&lt;p&gt;Writing these articles helps me reinforce what I've learned, and hopefully helps other beginners who are on the same journey. 🤝&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate your corrections in the comments. 😊&lt;/p&gt;


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

&lt;p&gt;Today's class answered a question I didn't even know I had.&lt;/p&gt;

&lt;p&gt;I always thought React automatically "noticed" when variables changed.&lt;/p&gt;

&lt;p&gt;Now I know that's not true.&lt;/p&gt;

&lt;p&gt;React only reacts to &lt;strong&gt;state&lt;/strong&gt;, and the bridge between my code and React is &lt;strong&gt;Hooks&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Learning &lt;code&gt;useState&lt;/code&gt; made me realize that React isn't watching every variable in my application. It's only watching the state that I choose to manage through Hooks.&lt;/p&gt;

&lt;p&gt;That small detail completely changed how I think about React.&lt;/p&gt;

&lt;p&gt;Tomorrow's topic is &lt;strong&gt;Batching&lt;/strong&gt;, and after today's lesson, I'm really curious to see how React groups multiple state updates together to make applications even more efficient.&lt;/p&gt;

&lt;p&gt;See you on Day 5! 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;When you first learned &lt;code&gt;useState&lt;/code&gt;, what surprised you the most? Was it that the setter function triggers a re-render, or that React completely skips updates when the value hasn't changed?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javasc</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 3 of Learning React: Understanding JSX, Components, Props, Bundlers, and What Happens After `npm run dev`</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Wed, 24 Jun 2026 22:11:34 +0000</pubDate>
      <link>https://dev.to/bismay-exe/react-learning-journey-day-3-understanding-jsx-components-props-bundlers-and-what-happens-56i8</link>
      <guid>https://dev.to/bismay-exe/react-learning-journey-day-3-understanding-jsx-components-props-bundlers-and-what-happens-56i8</guid>
      <description>&lt;p&gt;📌 &lt;em&gt;Missed Day 2? I covered how React updates the UI internally—Reconciliation, the Diffing Algorithm, Render Phase, Commit Phase, Browser Paint, and React Fiber. You can &lt;a href="https://dev.to/bismay-exe/day-2-of-learning-react-reconciliation-diffing-algorithm-render-phase-commit-phase-react-4f0f"&gt;read it here&lt;/a&gt; and then come back. I'll wait. ☕️&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-2-of-learning-react-reconciliation-diffing-algorithm-render-phase-commit-phase-react-4f0f" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 2 of Learning React: Reconciliation, Diffing Algorithm, Render Phase, Commit Phase &amp;amp; React Fiber&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image" width="400" height="400"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-3972755" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt="" width="400" height="400"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-2-of-learning-react-reconciliation-diffing-algorithm-render-phase-commit-phase-react-4f0f" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jun 23&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-2-of-learning-react-reconciliation-diffing-algorithm-render-phase-commit-phase-react-4f0f" id="article-link-3972755"&gt;
          🚀 Day 2 of Learning React: Reconciliation, Diffing Algorithm, Render Phase, Commit Phase &amp;amp; React Fiber
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-2-of-learning-react-reconciliation-diffing-algorithm-render-phase-commit-phase-react-4f0f" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;12&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-2-of-learning-react-reconciliation-diffing-algorithm-render-phase-commit-phase-react-4f0f#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              2&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            11 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;Yesterday I finally understood &lt;strong&gt;how React updates the UI.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I thought that was enough.&lt;/p&gt;

&lt;p&gt;But today's class made me realize I was still treating React like magic.&lt;/p&gt;

&lt;p&gt;Every time I typed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;my project just started.&lt;/p&gt;

&lt;p&gt;I never stopped to ask what actually happens after pressing Enter. 🤔&lt;/p&gt;

&lt;p&gt;Today's session answered that question—and along the way, I also learned why JSX exists, how components communicate through props, and what a bundler is actually doing behind the scenes.&lt;/p&gt;

&lt;p&gt;Let's dive in. 🚀&lt;/p&gt;


&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday, we answered one big question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How does React update the UI?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I took away from &lt;strong&gt;Day 2&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔄 &lt;strong&gt;Reconciliation&lt;/strong&gt; is React's strategy for comparing two Virtual DOM trees.&lt;/li&gt;
&lt;li&gt;⚡ The &lt;strong&gt;Diffing Algorithm&lt;/strong&gt; efficiently finds the minimum set of changes.&lt;/li&gt;
&lt;li&gt;🎬 The &lt;strong&gt;Render Phase&lt;/strong&gt; is where React plans the updates—it doesn't touch the DOM yet.&lt;/li&gt;
&lt;li&gt;✅ The &lt;strong&gt;Commit Phase&lt;/strong&gt; is where those changes are applied to the Real DOM.&lt;/li&gt;
&lt;li&gt;🎨 Finally, the &lt;strong&gt;browser&lt;/strong&gt; handles Layout, Paint, and Composite to display everything on the screen.&lt;/li&gt;
&lt;li&gt;🧵 &lt;strong&gt;React Fiber&lt;/strong&gt; makes the Render Phase interruptible, allowing React to keep applications responsive.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yesterday was all about &lt;strong&gt;how React updates the UI.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Today, we're answering a different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What actually happens from the moment we type &lt;code&gt;npm run dev&lt;/code&gt; until our React app appears in the browser? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And along the way, I finally understood &lt;strong&gt;JSX, bundlers, components, and props.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That's where today's journey begins. 🔽&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 The Biggest Lesson of Today
&lt;/h2&gt;

&lt;p&gt;One realization stood out above everything else:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;React isn't magic. It's just a collection of tools working together in a smart way.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When I first saw React code, I imagined there was some hidden engine doing impossible things.&lt;/p&gt;

&lt;p&gt;But after learning about bundlers, JSX, transpilation, and rendering, I realized that every step has a purpose.&lt;/p&gt;

&lt;p&gt;Once you understand those steps, React becomes much easier to learn.&lt;/p&gt;


&lt;h2&gt;
  
  
  What Really Happens When You Run &lt;code&gt;npm run dev&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Before today, I thought this command simply "started React."&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Turns out, &lt;strong&gt;a lot happens behind the scenes.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's the simplified flow that finally made sense to me:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
        │
        ▼
 Development Server Starts
        │
        ▼
 Bundler Processes Files
        │
        ▼
 JSX is Transpiled
        │
        ▼
 JavaScript is Bundled
        │
        ▼
 Browser Executes the Bundle
        │
        ▼
 React Creates/Updates the DOM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Seeing this pipeline helped me understand that React isn't directly executed by the browser.&lt;/p&gt;

&lt;p&gt;The browser only understands &lt;strong&gt;JavaScript&lt;/strong&gt;, &lt;strong&gt;HTML&lt;/strong&gt;, and &lt;strong&gt;CSS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Everything else has to be converted first.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚙️ What Really Happens When I Run npm run dev?
&lt;/h2&gt;

&lt;p&gt;When I type:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I'm not actually starting React itself.&lt;/p&gt;

&lt;p&gt;Instead, I'm starting a &lt;strong&gt;development server&lt;/strong&gt;, usually powered by tools like &lt;strong&gt;Vite&lt;/strong&gt;.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Watches my files&lt;/li&gt;
&lt;li&gt;Rebuilds the project when I save&lt;/li&gt;
&lt;li&gt;Refreshes the browser automatically&lt;/li&gt;
&lt;li&gt;Makes development much faster&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why changes appear almost instantly without manually refreshing the page.&lt;/p&gt;


&lt;h2&gt;
  
  
  📦 Bundlers — The Part I Never Thought About
&lt;/h2&gt;

&lt;p&gt;This was one of my favorite topics today.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;bundler&lt;/strong&gt; collects all the files in a project and combines them into something the browser can understand efficiently.&lt;/p&gt;

&lt;p&gt;Imagine a React project with:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;App.jsx
Navbar.jsx
Footer.jsx
Button.jsx
styles.css
utils.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead of sending dozens of separate files to the browser, the bundler organizes and prepares them into optimized bundles.&lt;/p&gt;

&lt;p&gt;Popular bundlers include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vite (uses esbuild during development and Rollup for production)&lt;/li&gt;
&lt;li&gt;Webpack&lt;/li&gt;
&lt;li&gt;Parcel&lt;/li&gt;
&lt;li&gt;Rollup&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without bundlers, managing large applications would be much more difficult.&lt;/p&gt;


&lt;h2&gt;
  
  
  🤯 JSX Isn't HTML... and It Isn't JavaScript Either
&lt;/h2&gt;

&lt;p&gt;This surprised me the most.&lt;/p&gt;

&lt;p&gt;I used to think JSX was just JavaScript.&lt;/p&gt;

&lt;p&gt;It's not.&lt;/p&gt;

&lt;p&gt;Consider this code:&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;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;&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 React!&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;Browsers don't understand:&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="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello React!&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Something has to convert it first.&lt;/p&gt;

&lt;p&gt;That's where &lt;strong&gt;Babel&lt;/strong&gt; (or another JSX transformer) comes in.&lt;/p&gt;

&lt;p&gt;It transforms JSX into regular JavaScript.&lt;/p&gt;

&lt;p&gt;Conceptually, it becomes something 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="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="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello 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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The browser can execute the transformed JavaScript, not the original JSX.&lt;/p&gt;

&lt;p&gt;Understanding this made JSX feel much less "magical."&lt;/p&gt;


&lt;h2&gt;
  
  
  ✨ JSX Makes UI Easier to Read
&lt;/h2&gt;

&lt;p&gt;Even though JSX is transformed behind the scenes, it makes code much more readable.&lt;/p&gt;

&lt;p&gt;Instead of writing lots of &lt;code&gt;createElement()&lt;/code&gt; calls, we can write something that looks like HTML.&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 jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Welcome&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&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="nt"&gt;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Welcome 👋&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I'm learning React!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&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="nt"&gt;div&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It's cleaner, easier to understand, and much more enjoyable to work with.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧩 Components — Finally, They Clicked
&lt;/h2&gt;

&lt;p&gt;Another concept that clicked today was &lt;strong&gt;components&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of creating one giant HTML page, React encourages breaking the UI into small reusable pieces.&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 jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Header&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;My Blog&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;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Footer&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;footer&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Made with ❤️&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;footer&lt;/span&gt;&lt;span class="p"&gt;&amp;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="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Header&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;Footer&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&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;This approach makes applications:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easier to read&lt;/li&gt;
&lt;li&gt;Easier to maintain&lt;/li&gt;
&lt;li&gt;Easier to reuse&lt;/li&gt;
&lt;li&gt;Easier to test&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I can already see why React applications stay organized even as they grow.&lt;/p&gt;


&lt;h2&gt;
  
  
  📨 Props — How Components Talk to Each Other
&lt;/h2&gt;

&lt;p&gt;Components become much more powerful when they receive data.&lt;/p&gt;

&lt;p&gt;That's where &lt;strong&gt;props&lt;/strong&gt; come in.&lt;/p&gt;

&lt;p&gt;Here's a simple example:&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;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;props&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h2&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;props&lt;/span&gt;&lt;span class="p"&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;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="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Greeting&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Alice"&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;Greeting&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Bob"&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;Greeting&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Charlie"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&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;Instead of creating three different greeting components, we create one reusable component and pass different values through props.&lt;/p&gt;

&lt;p&gt;This was my first glimpse into how React promotes reusable code.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧠 My Mental Model of React So Far
&lt;/h2&gt;

&lt;p&gt;After today's learning, here's how I now think about React:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Component
      │
      ▼
Returns JSX
      │
      ▼
JSX is Transformed
      │
      ▼
JavaScript Executes
      │
      ▼
React Creates UI
      │
      ▼
Browser Displays It
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Breaking the process into steps makes it far less intimidating.&lt;/p&gt;


&lt;h2&gt;
  
  
  🌳 The Final Step — React Still Ends Up Updating the DOM
&lt;/h2&gt;

&lt;p&gt;One question I had was:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"If something changes, does React rebuild the whole page?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The answer is &lt;strong&gt;no&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;React figures out &lt;strong&gt;what actually changed&lt;/strong&gt; and updates only those parts of the page.&lt;/p&gt;

&lt;p&gt;For example, if only a counter value changes:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Counter: 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React doesn't recreate the entire application.&lt;/p&gt;

&lt;p&gt;It updates only the specific element that changed, making applications faster and more efficient.&lt;/p&gt;

&lt;p&gt;This efficient update strategy is one reason React feels so responsive.&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways
&lt;/h2&gt;

&lt;p&gt;Today's session taught me that learning React isn't just about memorizing syntax.&lt;/p&gt;

&lt;p&gt;It's about understanding the journey from writing code to seeing something on the screen.&lt;/p&gt;

&lt;p&gt;Here are the ideas that stuck with me the most:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚙️ &lt;code&gt;npm run dev&lt;/code&gt; does much more than simply "run React."&lt;/li&gt;
&lt;li&gt;📦 Bundlers organize and optimize our application before it reaches the browser.&lt;/li&gt;
&lt;li&gt;✨ JSX isn't valid JavaScript—it gets transformed before execution.&lt;/li&gt;
&lt;li&gt;🧩 Components make building UIs modular and reusable.&lt;/li&gt;
&lt;li&gt;📨 Props allow components to communicate by passing data.&lt;/li&gt;
&lt;li&gt;🌳 Understanding what happens behind the scenes makes React feel far less magical.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These concepts have given me a much stronger foundation for the topics I'll learn next.&lt;/p&gt;


&lt;h2&gt;
  
  
  🚀 What's Next?
&lt;/h2&gt;

&lt;p&gt;I'm excited to continue exploring React.&lt;/p&gt;

&lt;p&gt;The next concepts on my list include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State&lt;/li&gt;
&lt;li&gt;Event handling&lt;/li&gt;
&lt;li&gt;Hooks like &lt;code&gt;useState&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Rendering lists&lt;/li&gt;
&lt;li&gt;Conditional rendering&lt;/li&gt;
&lt;li&gt;Building small projects&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I know there will be challenges ahead, but understanding the fundamentals has made me much more confident.&lt;/p&gt;


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

&lt;p&gt;Day 3 wasn't about building flashy applications—it was about building understanding.&lt;/p&gt;

&lt;p&gt;Before today, commands like &lt;code&gt;npm run dev&lt;/code&gt; and concepts like JSX felt like magic. Now, I can see the moving parts behind the scenes. Knowing that a development server starts, a bundler prepares my files, JSX gets transformed into JavaScript, and React updates the DOM step by step has made the framework feel much more approachable.&lt;/p&gt;

&lt;p&gt;I've realized that becoming a better developer isn't just about making things work. It's about understanding &lt;strong&gt;why&lt;/strong&gt; they work. That mindset is something I want to carry throughout my entire learning journey.&lt;/p&gt;

&lt;p&gt;If you're just starting React too, don't rush through the basics. The deeper your foundation, the easier everything else becomes.&lt;/p&gt;

&lt;p&gt;Thanks for reading! If you're on your own React journey, I'd love to hear what clicked for you recently. Let's keep learning together, one component at a time. 🚀💙&lt;/p&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the &lt;strong&gt;React Cohort 3.0&lt;/strong&gt; by &lt;strong&gt;Devendra Dhote&lt;/strong&gt; at &lt;strong&gt;Sheriyans Coding School&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This article isn't a copy of the course.&lt;/p&gt;

&lt;p&gt;It's my personal understanding after today's class, rewritten entirely in my own words.&lt;/p&gt;

&lt;p&gt;Writing these articles helps me reinforce what I've learned, and hopefully helps other beginners who are on the same journey. 🤝&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate your corrections in the comments. 😊&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;When you first started React, which concept confused you the most—JSX, components, props, or understanding what &lt;code&gt;npm run dev&lt;/code&gt; actually does?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 2 of Learning React: Reconciliation, Diffing Algorithm, Render Phase, Commit Phase &amp; React Fiber</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Tue, 23 Jun 2026 19:03:57 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-2-of-learning-react-reconciliation-diffing-algorithm-render-phase-commit-phase-react-4f0f</link>
      <guid>https://dev.to/bismay-exe/day-2-of-learning-react-reconciliation-diffing-algorithm-render-phase-commit-phase-react-4f0f</guid>
      <description>&lt;p&gt;📌 &lt;em&gt;Missed Day 1? I covered why React exists, the Real DOM, Virtual DOM, and React Elements. You can &lt;a href="https://dev.to/bismay_exe/day-1-of-learning-react-why-react-exists-the-real-dom-virtual-dom-react-elements-43gm"&gt;read it here&lt;/a&gt; and then come back. I'll wait. ☕&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/bismay-exe/day-1-of-learning-react-why-react-exists-the-real-dom-virtual-dom-react-elements-5b61" class="crayons-story__hidden-navigation-link"&gt;🚀 Day 1 of Learning React: Why React Exists, the Real DOM, Virtual DOM &amp;amp; React Elements&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/bismay-exe" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" alt="bismay-exe profile" class="crayons-avatar__image" width="400" height="400"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/bismay-exe" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Bismay.exe
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Bismay.exe
                
              
              &lt;div id="story-author-preview-content-3964538" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/bismay-exe" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3452916%2Fa88e3dae-8b83-489c-b423-44ef7013e8e2.gif" class="crayons-avatar__image" alt="" width="400" height="400"&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Bismay.exe&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/bismay-exe/day-1-of-learning-react-why-react-exists-the-real-dom-virtual-dom-react-elements-5b61" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jun 22&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/bismay-exe/day-1-of-learning-react-why-react-exists-the-real-dom-virtual-dom-react-elements-5b61" id="article-link-3964538"&gt;
          🚀 Day 1 of Learning React: Why React Exists, the Real DOM, Virtual DOM &amp;amp; React Elements
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/bismay-exe/day-1-of-learning-react-why-react-exists-the-real-dom-virtual-dom-react-elements-5b61" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/exploding-head-daceb38d627e6ae9b730f36a1e390fca556a4289d5a41abb2c35068ad3e2c4b5.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="24" height="24"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;12&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/bismay-exe/day-1-of-learning-react-why-react-exists-the-real-dom-virtual-dom-react-elements-5b61#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              &lt;span class="hidden s:inline"&gt;Add&amp;nbsp;Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            4 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success crayons-icon c-btn__icon"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;





&lt;p&gt;Today was genuinely one of those sessions where you go in confused and come out feeling like you unlocked a new level.&lt;/p&gt;

&lt;p&gt;Yesterday I learned &lt;em&gt;what&lt;/em&gt; React does—it keeps a Virtual DOM in memory and updates only the parts of the Real DOM that actually changed.&lt;/p&gt;

&lt;p&gt;Cool. Makes sense.&lt;/p&gt;

&lt;p&gt;But one question kept bugging me all night:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;How does React actually know what changed? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Today's class answered that question. And honestly? It completely changed how I think about React.&lt;/p&gt;

&lt;p&gt;Let's get into it. 🚀&lt;/p&gt;




&lt;h2&gt;
  
  
  🧠 Quick Recap
&lt;/h2&gt;

&lt;p&gt;Yesterday we answered one question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Why was React created?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here's what I took away from Day 1:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔧 Manually updating the DOM in large apps becomes unmanageable.&lt;/li&gt;
&lt;li&gt;💡 React introduced &lt;strong&gt;UI = Function(State)&lt;/strong&gt;—we describe what we want, React handles the updates.&lt;/li&gt;
&lt;li&gt;📦 A &lt;strong&gt;React Element&lt;/strong&gt; is just a plain JavaScript object that &lt;em&gt;describes&lt;/em&gt; UI. It's not a real DOM node.&lt;/li&gt;
&lt;li&gt;🌳 The &lt;strong&gt;Virtual DOM&lt;/strong&gt; is a lightweight copy of the UI that lives entirely in JavaScript memory.&lt;/li&gt;
&lt;li&gt;⚡ React compares changes in the Virtual DOM and updates only the necessary parts of the Real DOM.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today we're answering a completely different question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;How does React actually update the UI?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's where today's journey begins. 🔽&lt;/p&gt;




&lt;h2&gt;
  
  
  🔄 Reconciliation — How React Knows What Changed
&lt;/h2&gt;

&lt;p&gt;This is the concept that finally tied everything together for me.&lt;/p&gt;

&lt;p&gt;I kept thinking, "Okay, React compares two trees. But... &lt;em&gt;how?&lt;/em&gt; And what does that even look like?"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reconciliation&lt;/strong&gt; is React's process for figuring out what changed between two renders.&lt;/p&gt;

&lt;p&gt;Here's how I think about it. 🖊️&lt;/p&gt;

&lt;p&gt;Imagine you're editing an essay. You've got the original version and a revised version side by side. Instead of rewriting the entire essay, you scan through both versions and find only the sentences that actually changed. Then you update just those.&lt;/p&gt;

&lt;p&gt;That's essentially what React does—except it's comparing two Virtual DOM trees.&lt;/p&gt;

&lt;p&gt;When something changes in your app (say, a button click updates some text), React doesn't throw away the entire UI and rebuild it from scratch. Instead, it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creates a &lt;strong&gt;new&lt;/strong&gt; Virtual DOM tree based on the updated state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Compares&lt;/strong&gt; it with the previous Virtual DOM tree.&lt;/li&gt;
&lt;li&gt;Figures out the &lt;strong&gt;minimum set of changes&lt;/strong&gt; needed.&lt;/li&gt;
&lt;li&gt;Applies only those changes to the Real DOM.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here's a small example. Let's say our component renders this:&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 state change&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&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 after a state update, it renders this:&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;// After state change&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello React&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;React compares these two trees and realizes: "The &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; element is the same type, but the text inside changed from &lt;code&gt;Hello&lt;/code&gt; to &lt;code&gt;Hello React&lt;/code&gt;. I only need to update the text content."&lt;/p&gt;

&lt;p&gt;That comparison process? That's reconciliation. 🔄&lt;/p&gt;

&lt;p&gt;But here's the thing—reconciliation is just the &lt;em&gt;strategy&lt;/em&gt;. The actual comparison happens through something more specific.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚡ Diffing Algorithm — The Engine Behind Reconciliation
&lt;/h2&gt;

&lt;p&gt;So how does React actually compare two Virtual DOM trees?&lt;/p&gt;

&lt;p&gt;That's where the &lt;strong&gt;diffing algorithm&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;If reconciliation is the &lt;em&gt;what&lt;/em&gt; ("figure out what changed"), diffing is the &lt;em&gt;how&lt;/em&gt; ("here's how I compare the two trees").&lt;/p&gt;

&lt;p&gt;Now, this part surprised me. 🤯&lt;/p&gt;

&lt;p&gt;Comparing two trees might sound simple, but it's actually a hard computer science problem. A generic algorithm to compare two trees has a time complexity of &lt;strong&gt;O(n³)&lt;/strong&gt;—which means for a tree with 1,000 elements, it could take a &lt;em&gt;billion&lt;/em&gt; operations.&lt;/p&gt;

&lt;p&gt;That's way too slow for a UI library.&lt;/p&gt;

&lt;p&gt;I paused the video here. I was like, "Wait... React does this on &lt;em&gt;every single update?&lt;/em&gt; How is it fast?"&lt;/p&gt;

&lt;p&gt;That's when I learned about React's clever trade-off. Instead of finding the &lt;em&gt;perfect&lt;/em&gt; difference between two trees, the React team made a few practical assumptions that are almost always true in real-world applications. That keeps comparisons incredibly fast.&lt;/p&gt;

&lt;p&gt;They built their diffing algorithm on two key assumptions:&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Different types? Different trees. 🔀
&lt;/h3&gt;

&lt;p&gt;If React sees that a &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; changed to a &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt;, it doesn't bother comparing their children. It destroys the old tree and builds a new one from scratch.&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&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;p&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&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="c1"&gt;// After&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;section&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;p&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&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;p&gt;Even though the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; inside is identical, React tears down the entire &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; subtree and creates a new &lt;code&gt;&amp;lt;section&amp;gt;&lt;/code&gt; subtree. Different type = different tree. No questions asked.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Same type? Compare what changed. 🔎
&lt;/h3&gt;

&lt;p&gt;If the element type stays the same, React keeps the DOM node and only updates the attributes that actually changed.&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&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&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;className&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&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;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// After&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&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;className&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title active&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;Hello&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;Here, the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; is still an &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt;. React keeps the same DOM node and only updates the &lt;code&gt;className&lt;/code&gt;. Much more efficient. ⚡&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Keys help React identify list items 🔑
&lt;/h3&gt;

&lt;p&gt;When rendering lists, React uses &lt;strong&gt;keys&lt;/strong&gt; to track which items changed, moved, or were removed.&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;items&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="o"&gt;=&amp;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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;li&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;key&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;id&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;name&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;I'll cover keys in more depth later in this series, but for now, just know they exist to help the diffing algorithm identify list items efficiently.&lt;/p&gt;
&lt;h3&gt;
  
  
  💡 The biggest misconception I had
&lt;/h3&gt;

&lt;p&gt;I honestly thought React compared the Virtual DOM against the Real DOM.&lt;/p&gt;

&lt;p&gt;That's wrong. ❌&lt;/p&gt;

&lt;p&gt;React compares the &lt;strong&gt;new Virtual DOM&lt;/strong&gt; against the &lt;strong&gt;previous Virtual DOM&lt;/strong&gt;. The Real DOM is never part of the comparison. It only gets involved later, when React applies the changes.&lt;/p&gt;

&lt;p&gt;That distinction seems small, but once I understood it, the entire mental model just... clicked. 🧩&lt;/p&gt;

&lt;p&gt;Thanks to these assumptions, React's diffing algorithm runs in &lt;strong&gt;O(n)&lt;/strong&gt; time—one pass through the tree. That's what makes it fast enough for real-time UI updates.&lt;/p&gt;

&lt;p&gt;So now React knows exactly what changed. But it hasn't touched the Real DOM yet.&lt;/p&gt;

&lt;p&gt;What happens next? 🤔&lt;/p&gt;


&lt;h2&gt;
  
  
  🎬 Render Phase — Planning, Not Painting
&lt;/h2&gt;

&lt;p&gt;This is where things got really interesting for me.&lt;/p&gt;

&lt;p&gt;When I first heard "Render Phase," I assumed it meant React was drawing things on the screen.&lt;/p&gt;

&lt;p&gt;Nope. Not even close. 😅&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Render Phase&lt;/strong&gt; is a planning phase. React calls your components, builds the new Virtual DOM tree, and runs the diffing algorithm to figure out what needs to change. But it &lt;strong&gt;does not touch the Real DOM&lt;/strong&gt; during this phase.&lt;/p&gt;

&lt;p&gt;Think of it like an architect creating a blueprint. 📐 The architect plans every room, every wall, every window—but no construction has started yet. The Render Phase is React creating that blueprint.&lt;/p&gt;

&lt;p&gt;Here's what happens step by step:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Something triggers a re-render (state change, prop change, etc.)&lt;/li&gt;
&lt;li&gt;React calls your component function again.&lt;/li&gt;
&lt;li&gt;Your component returns new React Elements.&lt;/li&gt;
&lt;li&gt;React builds a new Virtual DOM tree from those elements.&lt;/li&gt;
&lt;li&gt;React diffs the new tree against the previous tree.&lt;/li&gt;
&lt;li&gt;React produces a list of changes that need to be applied.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let me show a simple 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;function&lt;/span&gt; &lt;span class="nf"&gt;Counter&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="nx"&gt;React&lt;/span&gt;&lt;span class="p"&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;return&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;p&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Count: &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;button&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;onClick&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="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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Increment&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;When you click "Increment," React enters the Render Phase:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It calls &lt;code&gt;Counter()&lt;/code&gt; again with the new state (&lt;code&gt;count = 1&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;It gets back a new tree where the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; now says "Count: 1" instead of "Count: 0".&lt;/li&gt;
&lt;li&gt;It diffs this against the old tree.&lt;/li&gt;
&lt;li&gt;It notes: "Only the text inside &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; changed."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At this point, the screen still shows "Count: 0". Nothing visible has changed yet. 👀&lt;/p&gt;

&lt;p&gt;I tried wrapping my head around this by opening VS Code and console-logging inside a component. The function runs again on every re-render—but the screen doesn't update until later. That's the Render Phase in action.&lt;/p&gt;

&lt;p&gt;That leads us to the next phase.&lt;/p&gt;


&lt;h2&gt;
  
  
  ✅ Commit Phase — Where the Real DOM Actually Changes
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Commit Phase&lt;/strong&gt; is where React actually applies the changes to the Real DOM.&lt;/p&gt;

&lt;p&gt;If the Render Phase is the architect drawing blueprints, the Commit Phase is the construction crew showing up and doing the work. 🏗️&lt;/p&gt;

&lt;p&gt;During this phase, React takes the list of changes it prepared during the Render Phase and makes the actual DOM updates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding new DOM nodes&lt;/li&gt;
&lt;li&gt;Removing old DOM nodes&lt;/li&gt;
&lt;li&gt;Updating attributes, text content, or event listeners&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For our counter example, the Commit Phase would:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find the &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; DOM node.&lt;/li&gt;
&lt;li&gt;Update its text content from "Count: 0" to "Count: 1".&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it. One targeted update instead of rebuilding the entire page. ✨&lt;/p&gt;

&lt;p&gt;Here's the key difference between the two phases:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;🎬 Render Phase&lt;/th&gt;
&lt;th&gt;✅ Commit Phase&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;What it does&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Plans changes&lt;/td&gt;
&lt;td&gt;Applies changes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Touches the DOM?&lt;/strong&gt;&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;&lt;strong&gt;Can be paused?&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;✅ Yes&lt;/td&gt;
&lt;td&gt;❌ No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Output&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;List of changes&lt;/td&gt;
&lt;td&gt;Updated DOM&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Notice that the Render Phase can be paused—I'll explain why that matters when we get to Fiber. 🧵&lt;/p&gt;

&lt;p&gt;The Commit Phase is synchronous. Once React starts applying changes to the DOM, it finishes all of them in one go without interruption.&lt;/p&gt;

&lt;p&gt;But even after the Commit Phase, we're not done. The DOM has been updated, but you still can't see anything different on screen. Something else needs to happen.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎨 Browser Paint — From DOM to Pixels
&lt;/h2&gt;

&lt;p&gt;Before today, I thought React drew everything on the screen.&lt;/p&gt;

&lt;p&gt;Turns out... React never paints a single pixel.&lt;/p&gt;

&lt;p&gt;The browser does.&lt;/p&gt;

&lt;p&gt;React's job ends after updating the DOM. That was a surprisingly big realization for me.&lt;/p&gt;

&lt;p&gt;After React updates the DOM in the Commit Phase, the &lt;strong&gt;browser&lt;/strong&gt; takes over. Now it needs to turn those DOM changes into actual pixels on your screen.&lt;/p&gt;

&lt;p&gt;This happens in three steps:&lt;/p&gt;

&lt;p&gt;📐 &lt;strong&gt;Layout&lt;/strong&gt; — The browser calculates the size and position of every element. If you changed the text inside a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;, the browser recalculates how much space that paragraph needs, and whether anything around it shifts.&lt;/p&gt;

&lt;p&gt;🎨 &lt;strong&gt;Paint&lt;/strong&gt; — The browser fills in the pixels. It draws the text, backgrounds, borders, shadows—everything visual.&lt;/p&gt;

&lt;p&gt;🧩 &lt;strong&gt;Composite&lt;/strong&gt; — The browser combines different layers (if any) into the final image you see on screen. Think of it like stacking transparent sheets on top of each other.&lt;/p&gt;

&lt;p&gt;The important thing I realized today is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;React updates the DOM. The browser paints the pixels. They're two separate steps.&lt;/strong&gt; 💡&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;React can't directly draw on the screen. It can only modify the DOM. The browser's rendering engine handles the rest.&lt;/p&gt;

&lt;p&gt;That's why React focuses so hard on making minimal DOM changes—because every change triggers the browser's layout, paint, and composite pipeline. Fewer changes = less work for the browser = smoother experience for the user. 🚀&lt;/p&gt;


&lt;h2&gt;
  
  
  🔁 The Complete React Update Cycle
&lt;/h2&gt;

&lt;p&gt;Now let's put everything together.&lt;/p&gt;

&lt;p&gt;This was the moment everything connected for me.&lt;/p&gt;

&lt;p&gt;Until now, I had been learning these concepts individually. Reconciliation. Diffing. Render Phase. Commit Phase. Browser Paint. They all made sense on their own, but I couldn't see how they fit together.&lt;/p&gt;

&lt;p&gt;Then I drew this out on paper during the class, and suddenly the entire system clicked. ✨&lt;/p&gt;

&lt;p&gt;When something changes in a React app, here's the full journey:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  State Change
       ↓
  Render Phase  (React calls components, builds new Virtual DOM)
       ↓
  Reconciliation  (Compare new vs old Virtual DOM)
       ↓
  Diffing  (Find minimum changes)
       ↓
  Commit Phase  (Apply changes to Real DOM)
       ↓
  Browser Paint  (Layout → Paint → Composite)
       ↓
  Pixels on Screen ✨
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Every single update—whether it's a button click, a form input, or data arriving from an API—follows this exact same cycle.&lt;/p&gt;

&lt;p&gt;Seeing them as one continuous pipeline completely changed my mental model of React. It stopped feeling like magic and started making sense as a system.&lt;/p&gt;

&lt;p&gt;But there's one more thing I learned today that tied everything together even further. 🧵&lt;/p&gt;


&lt;h2&gt;
  
  
  🧵 React Fiber — Why React Never Freezes Anymore
&lt;/h2&gt;

&lt;p&gt;When I first heard "Fiber," I honestly thought, "Great... another React buzzword."&lt;/p&gt;

&lt;p&gt;Turns out it's one of the most important architectural changes React has ever made. This section completely changed how I think about React's internals.&lt;/p&gt;

&lt;p&gt;Before React 16 (released in 2017), React's rendering was &lt;strong&gt;synchronous&lt;/strong&gt;. When React started rendering, it went through the entire component tree in one shot. It couldn't stop. It couldn't pause. It couldn't prioritize.&lt;/p&gt;

&lt;p&gt;Imagine you're watching a movie and you can't pause it. 🎬 Not even to answer the door. Not even if your house is on fire. You have to watch the entire thing from start to finish before you can do anything else.&lt;/p&gt;

&lt;p&gt;That was React before Fiber.&lt;/p&gt;

&lt;p&gt;For small apps, this was fine. But for large applications with complex component trees, a single render could take a while. During that time, the browser was completely blocked—no scrolling, no typing, no animations. Everything froze until React finished. 🥶&lt;/p&gt;

&lt;p&gt;I remember thinking, "Wait, React was like that? How did anyone build large apps with it?"&lt;/p&gt;

&lt;p&gt;That's the problem &lt;strong&gt;React Fiber&lt;/strong&gt; was built to solve.&lt;/p&gt;

&lt;p&gt;Fiber is a complete rewrite of React's core algorithm, introduced in React 16. It didn't change &lt;em&gt;what&lt;/em&gt; React does—it changed &lt;strong&gt;how&lt;/strong&gt; React does it.&lt;/p&gt;

&lt;p&gt;With Fiber, React can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⏸️ &lt;strong&gt;Pause&lt;/strong&gt; rendering work and come back to it later.&lt;/li&gt;
&lt;li&gt;🎯 &lt;strong&gt;Prioritize&lt;/strong&gt; different types of updates. A user typing in a text field is more urgent than a background data fetch.&lt;/li&gt;
&lt;li&gt;▶️ &lt;strong&gt;Resume&lt;/strong&gt; work that was paused without starting over.&lt;/li&gt;
&lt;li&gt;🗑️ &lt;strong&gt;Abort&lt;/strong&gt; work that's no longer needed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it like switching from watching a DVD (can't pause) to streaming on Netflix (pause, rewind, skip, switch to a different show, come back later). 📺&lt;/p&gt;

&lt;p&gt;The key insight is that Fiber makes React's Render Phase &lt;strong&gt;interruptible&lt;/strong&gt;. Remember how I said the Render Phase can be paused? That's because of Fiber. 💡&lt;/p&gt;

&lt;p&gt;The Commit Phase is still synchronous—once React starts applying changes to the DOM, it finishes without interruption. But the planning phase (Render Phase) can now be broken into chunks and spread across multiple frames, keeping the browser responsive.&lt;/p&gt;

&lt;p&gt;This is why modern React apps feel snappy even when dealing with complex updates. Fiber ensures that React never hogs the main thread for too long. ⚡&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚖️ Virtual DOM vs Fiber — They're Not the Same Thing
&lt;/h2&gt;

&lt;p&gt;This was confusing for me at first. I kept thinking: "Wait, did Fiber replace the Virtual DOM? Are they the same thing?"&lt;/p&gt;

&lt;p&gt;Nope. They're different concepts that work together. 🤝&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;🌳 Virtual DOM&lt;/th&gt;
&lt;th&gt;🧵 React Fiber&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;What it is&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A JavaScript representation of the UI&lt;/td&gt;
&lt;td&gt;React's reconciliation engine&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Purpose&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Describes what the UI should look like&lt;/td&gt;
&lt;td&gt;Manages how and when updates happen&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Introduced&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;React's original design&lt;/td&gt;
&lt;td&gt;React 16 (2017)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Handles&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;UI structure (the "what")&lt;/td&gt;
&lt;td&gt;Scheduling &amp;amp; prioritization (the "how")&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Here's how they work together:&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Virtual DOM&lt;/strong&gt; is still the concept—React keeps a lightweight JavaScript copy of your UI in memory and compares it to find changes. 🌳&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fiber&lt;/strong&gt; is the engine that &lt;em&gt;performs&lt;/em&gt; that comparison. It's the system that walks through the Virtual DOM tree, does the diffing, and decides when and how to apply updates to the Real DOM. 🧵&lt;/p&gt;

&lt;p&gt;So the Virtual DOM is the &lt;em&gt;data structure&lt;/em&gt; and Fiber is the &lt;em&gt;algorithm&lt;/em&gt; that operates on it.&lt;/p&gt;

&lt;p&gt;They're not competing concepts. Fiber is the reason the Virtual DOM approach works efficiently at scale. ⚖️&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 My Biggest Takeaways Today
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🔄 &lt;strong&gt;Reconciliation&lt;/strong&gt; is React's strategy—compare two Virtual DOM trees and find the minimum changes.&lt;/li&gt;
&lt;li&gt;⚡ The &lt;strong&gt;diffing algorithm&lt;/strong&gt; runs in O(n) time because of two smart assumptions about how UIs typically change.&lt;/li&gt;
&lt;li&gt;🎬 The &lt;strong&gt;Render Phase&lt;/strong&gt; is just planning. No DOM changes happen here.&lt;/li&gt;
&lt;li&gt;✅ The &lt;strong&gt;Commit Phase&lt;/strong&gt; is where React actually updates the Real DOM.&lt;/li&gt;
&lt;li&gt;🧵 &lt;strong&gt;Fiber&lt;/strong&gt; makes the Render Phase interruptible, so React never freezes the browser.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  📚 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the &lt;strong&gt;React Cohort 3.0&lt;/strong&gt; by &lt;strong&gt;Devendra Dhote&lt;/strong&gt; at &lt;strong&gt;Sheriyans Coding School&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This article isn't a copy of the course.&lt;/p&gt;

&lt;p&gt;It's my personal understanding after today's class, rewritten entirely in my own words.&lt;/p&gt;

&lt;p&gt;Writing these articles helps me reinforce what I've learned, and hopefully helps other beginners who are on the same journey. 🤝&lt;/p&gt;

&lt;p&gt;If I've misunderstood something, I'd genuinely appreciate your corrections in the comments. 😊&lt;/p&gt;


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

&lt;p&gt;Day 2 gave me a much deeper appreciation for what's happening behind the scenes in React.&lt;/p&gt;

&lt;p&gt;Yesterday I understood the &lt;em&gt;what&lt;/em&gt;. Today I understood the &lt;em&gt;how&lt;/em&gt;. And honestly, that shift in understanding makes me way more excited to keep going. 🔥&lt;/p&gt;

&lt;p&gt;Tomorrow I'm moving to &lt;strong&gt;Day 3&lt;/strong&gt;, where I'll finally start getting hands-on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✏️ JSX&lt;/li&gt;
&lt;li&gt;⚡ Vite&lt;/li&gt;
&lt;li&gt;📁 Project Structure&lt;/li&gt;
&lt;li&gt;🧩 Fragments&lt;/li&gt;
&lt;li&gt;🔒 Strict Mode&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I've been dying to write actual React code instead of just learning theory. Day 3 is where it gets real. 💻&lt;/p&gt;

&lt;p&gt;See you there! 🚀&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;When you first learned about React's update cycle, what was the hardest part to wrap your head around—Reconciliation, Fiber, or something else entirely?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>🚀 Day 1 of Learning React: Why React Exists, the Real DOM, Virtual DOM &amp; React Elements</title>
      <dc:creator>Bismay.exe</dc:creator>
      <pubDate>Mon, 22 Jun 2026 19:28:37 +0000</pubDate>
      <link>https://dev.to/bismay-exe/day-1-of-learning-react-why-react-exists-the-real-dom-virtual-dom-react-elements-5b61</link>
      <guid>https://dev.to/bismay-exe/day-1-of-learning-react-why-react-exists-the-real-dom-virtual-dom-react-elements-5b61</guid>
      <description>&lt;p&gt;Today marks &lt;strong&gt;Day 1&lt;/strong&gt; of my React journey.&lt;/p&gt;

&lt;p&gt;I've decided to document everything I learn—not because I'm an expert, but because I believe sharing the learning process can help other beginners while also helping me understand concepts better.&lt;/p&gt;

&lt;p&gt;Today's goal wasn't to build an app.&lt;/p&gt;

&lt;p&gt;It was to answer one simple question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Why was React created in the first place? 🤔&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's dive in.&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 Why Was React Created?
&lt;/h2&gt;

&lt;p&gt;Before React existed, developers built interactive websites by directly manipulating the browser's DOM using JavaScript or jQuery.&lt;/p&gt;

&lt;p&gt;For 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;heading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;heading&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This works perfectly for small applications.&lt;/p&gt;

&lt;p&gt;But imagine building something like Facebook.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📰 News Feed&lt;/li&gt;
&lt;li&gt;💬 Messages&lt;/li&gt;
&lt;li&gt;❤️ Likes&lt;/li&gt;
&lt;li&gt;🔔 Notifications&lt;/li&gt;
&lt;li&gt;💭 Comments&lt;/li&gt;
&lt;li&gt;👥 Friends List&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each part of the page can update independently.&lt;/p&gt;

&lt;p&gt;As applications grow larger, manually deciding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Which DOM node should update&lt;/li&gt;
&lt;li&gt;When it should update&lt;/li&gt;
&lt;li&gt;What else depends on it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;becomes increasingly difficult.&lt;/p&gt;

&lt;p&gt;That's where React changed everything.&lt;/p&gt;

&lt;p&gt;Instead of manually updating the UI, React introduced a much simpler idea:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;UI = Function(State)&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You describe &lt;strong&gt;what the UI should look like&lt;/strong&gt;, and React figures out &lt;strong&gt;how to efficiently update the browser.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I think that's a really elegant way to think about building user interfaces.&lt;/p&gt;


&lt;h2&gt;
  
  
  🌳 What Is the Real DOM?
&lt;/h2&gt;

&lt;p&gt;When the browser reads your HTML, it creates a tree-like structure called the &lt;strong&gt;Document Object Model (DOM).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For 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;body&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;main&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/main&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The browser sees something like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Document
└── body
    └── main
        └── h1
            └── Hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is called the &lt;strong&gt;Real DOM&lt;/strong&gt; because it's managed directly by the browser.&lt;/p&gt;

&lt;p&gt;Whenever something changes, the browser may need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📐 Recalculate layouts&lt;/li&gt;
&lt;li&gt;🎨 Repaint elements&lt;/li&gt;
&lt;li&gt;🖥️ Update the screen&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These operations become expensive in large applications.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚛️ What Is a React Element?
&lt;/h2&gt;

&lt;p&gt;One thing that surprised me today was learning that React doesn't immediately create HTML elements.&lt;/p&gt;

&lt;p&gt;When we write:&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;element&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello React&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;React actually creates a plain JavaScript object like this:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;children&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 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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This object is called a &lt;strong&gt;React Element&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A React Element is simply a &lt;strong&gt;description of what the UI should look like.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It isn't a real DOM node.&lt;/p&gt;

&lt;p&gt;That small distinction helped me understand React much better.&lt;/p&gt;


&lt;h2&gt;
  
  
  🧠 What Is the Virtual DOM?
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Virtual DOM&lt;/strong&gt; is another concept I finally understood today.&lt;/p&gt;

&lt;p&gt;It's basically a JavaScript representation of the UI that lives entirely in memory.&lt;/p&gt;

&lt;p&gt;For 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;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;World&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React internally represents it as something similar to:&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="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;children&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="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;children&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;Hello&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="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;children&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;World&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="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;The important thing I learned is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The Virtual DOM doesn't exist inside the browser. It only exists in JavaScript memory.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;React compares changes in this virtual representation and updates only the parts of the Real DOM that actually changed.&lt;/p&gt;

&lt;p&gt;That's one of the reasons React applications stay efficient.&lt;/p&gt;


&lt;h2&gt;
  
  
  🎯 What Happens During the First Render?
&lt;/h2&gt;

&lt;p&gt;When React renders an application for the first time:&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;root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;main&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;root&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="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;h1&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello 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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The process looks something like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;React Element
      ↓
Virtual DOM
      ↓
Real DOM
      ↓
Browser Screen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;React creates the necessary DOM nodes and finally displays them in the browser.&lt;/p&gt;


&lt;h2&gt;
  
  
  ✨ My Biggest Takeaway Today
&lt;/h2&gt;

&lt;p&gt;Today's lesson completely changed how I thought about React.&lt;/p&gt;

&lt;p&gt;Before today I assumed React was simply another JavaScript library.&lt;/p&gt;

&lt;p&gt;Now I realize it's actually &lt;strong&gt;a different way of thinking about building user interfaces.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Instead of telling the browser &lt;em&gt;how&lt;/em&gt; to update every single element...&lt;/p&gt;

&lt;p&gt;React lets us describe &lt;em&gt;what&lt;/em&gt; we want the UI to look like.&lt;/p&gt;

&lt;p&gt;That shift in mindset is what makes React so powerful.&lt;/p&gt;


&lt;h2&gt;
  
  
  📚 What I'm Learning Next
&lt;/h2&gt;

&lt;p&gt;Today's lesson covered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Why React?&lt;/li&gt;
&lt;li&gt;✅ Problems React Solves&lt;/li&gt;
&lt;li&gt;✅ History of React&lt;/li&gt;
&lt;li&gt;✅ SPA vs MPA&lt;/li&gt;
&lt;li&gt;✅ React Elements&lt;/li&gt;
&lt;li&gt;✅ ReactDOM&lt;/li&gt;
&lt;li&gt;✅ Virtual DOM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tomorrow I'll continue with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🔄 Reconciliation&lt;/li&gt;
&lt;li&gt;⚡ Diffing Algorithm&lt;/li&gt;
&lt;li&gt;🎨 Render Phase&lt;/li&gt;
&lt;li&gt;✅ Commit Phase&lt;/li&gt;
&lt;li&gt;🧵 React Fiber Architecture&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'll continue documenting everything I learn as I go. 🚀&lt;/p&gt;


&lt;h2&gt;
  
  
  📖 Learning Source
&lt;/h2&gt;

&lt;p&gt;I'm currently learning React through the React course by &lt;strong&gt;Devendra Dhote&lt;/strong&gt; at &lt;strong&gt;Sheriyans Coding School&lt;/strong&gt;. These posts are my own notes and understanding of each day's lessons, written in my own words as I continue learning.&lt;/p&gt;

&lt;p&gt;If I misunderstand any concept, feel free to correct me in the comments—I'm here to learn. 😊&lt;/p&gt;


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

&lt;p&gt;This is only &lt;strong&gt;Day 1&lt;/strong&gt;, but I'm already enjoying the journey.&lt;/p&gt;

&lt;p&gt;I'm sure there will be confusing concepts, bugs, and plenty of mistakes along the way—but that's part of learning.&lt;/p&gt;

&lt;p&gt;If you're also starting React from scratch, let's learn together.&lt;/p&gt;

&lt;p&gt;See you in &lt;strong&gt;Day 2! 🚀&lt;/strong&gt;&lt;/p&gt;



&lt;p&gt;💬 &lt;strong&gt;What was the hardest React concept for you when you started?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'd love to hear your experience in the comments. 😊&lt;/p&gt;

&lt;p&gt;If you're following along with this series, you can also find me on &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer"&gt;&lt;strong&gt;GitHub&lt;/strong&gt;&lt;/a&gt;, where I'll be sharing my projects and documenting my progress.&lt;/p&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/Bismay-exe" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F132383245%3Fv%3D4%3Fs%3D400" height="460" class="m-0" width="460"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/Bismay-exe" rel="noopener noreferrer" class="c-link"&gt;
            Bismay-exe (Bismay.exe) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            👋 Hi, I’m Bismay
💻 Developer passionate about building clean, minimal, and elegant apps
🚀 Focused on coding
🌱 Always learning, creating &amp;amp; new ideas - Bismay-exe
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;🤖 &lt;strong&gt;AI Disclosure:&lt;/strong&gt; This article is based on my own React learning journey, class notes, code experiments, and understanding. I used ChatGPT to help improve the writing, structure, and readability of this post. I reviewed and verified the technical explanations before publishing, and I take responsibility for everything shared here.&lt;/p&gt;

&lt;p&gt;Thanks for reading! 🚀&lt;/p&gt;




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