<?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: Kathirvel S</title>
    <description>The latest articles on DEV Community by Kathirvel S (@kathirvel-s).</description>
    <link>https://dev.to/kathirvel-s</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3689425%2F49462e6b-f95a-4bb0-b5e3-080ad3919937.jpeg</url>
      <title>DEV Community: Kathirvel S</title>
      <link>https://dev.to/kathirvel-s</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kathirvel-s"/>
    <language>en</language>
    <item>
      <title>Mastering useReducer in React — The Hook That Simplifies Complex State</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Tue, 12 May 2026 15:16:44 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/mastering-usereducer-in-react-the-hook-that-simplifies-complex-state-3idl</link>
      <guid>https://dev.to/kathirvel-s/mastering-usereducer-in-react-the-hook-that-simplifies-complex-state-3idl</guid>
      <description>&lt;h3&gt;
  
  
  From Simple State to Scalable Logic
&lt;/h3&gt;

&lt;p&gt;Welcome back to another episode of &lt;strong&gt;“Let’s Master React Hooks Together”&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;React always feels easy at the beginning.&lt;/p&gt;

&lt;p&gt;You learn components.&lt;br&gt;
You learn props.&lt;br&gt;
You learn useState.&lt;/p&gt;

&lt;p&gt;Everything feels smooth.&lt;/p&gt;

&lt;p&gt;But then real applications arrive.&lt;/p&gt;

&lt;p&gt;And suddenly state logic starts growing fast:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;multiple form fields&lt;/li&gt;
&lt;li&gt;loading states&lt;/li&gt;
&lt;li&gt;error handling&lt;/li&gt;
&lt;li&gt;API responses&lt;/li&gt;
&lt;li&gt;step-based flows&lt;/li&gt;
&lt;li&gt;conditional updates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And your component slowly becomes harder to manage.&lt;/p&gt;

&lt;p&gt;This is where most developers get stuck.&lt;/p&gt;

&lt;p&gt;Because useState works perfectly… until it doesn’t.&lt;/p&gt;

&lt;p&gt;That’s where useReducer enters.&lt;/p&gt;

&lt;p&gt;Not as a replacement.&lt;/p&gt;

&lt;p&gt;But as a way to bring structure when state starts becoming complex.&lt;/p&gt;


&lt;h1&gt;
  
  
  In This Episode, You’ll Learn
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;What useReducer actually is&lt;/li&gt;
&lt;li&gt;How state flows through it&lt;/li&gt;
&lt;li&gt;How actions connect everything&lt;/li&gt;
&lt;li&gt;How dispatch triggers updates&lt;/li&gt;
&lt;li&gt;Real-world patterns&lt;/li&gt;
&lt;li&gt;Multi-step form logic&lt;/li&gt;
&lt;li&gt;When to use it and when not to&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And most importantly…&lt;/p&gt;

&lt;p&gt;You’ll see how scattered state turns into a clean, predictable flow.&lt;/p&gt;


&lt;h1&gt;
  
  
  What is useReducer in React?
&lt;/h1&gt;

&lt;p&gt;At its core, useReducer follows one simple idea:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Instead of changing state directly, you describe what happened, and React figures out how the state should change.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That movement always follows the same path:&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;Action&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;Reducer&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;New&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each part has a role:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Action carries the event&lt;/li&gt;
&lt;li&gt;Reducer decides the change&lt;/li&gt;
&lt;li&gt;State stores the result&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Why This Pattern Exists
&lt;/h1&gt;

&lt;p&gt;Think about a login screen.&lt;/p&gt;

&lt;p&gt;You are dealing with multiple values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;email&lt;/li&gt;
&lt;li&gt;password&lt;/li&gt;
&lt;li&gt;loading&lt;/li&gt;
&lt;li&gt;error&lt;/li&gt;
&lt;li&gt;success&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If each one is handled separately, updates happen in different places, and logic becomes scattered.&lt;/p&gt;

&lt;p&gt;Over time, it becomes harder to track how everything connects.&lt;/p&gt;

&lt;p&gt;The idea of a reducer is to bring all these changes into one controlled place where every update follows the same path.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Foundation
&lt;/h1&gt;

&lt;p&gt;Everything starts with this line:&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="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;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a connection between three things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;state → holds current values&lt;/li&gt;
&lt;li&gt;dispatch → sends a signal&lt;/li&gt;
&lt;li&gt;reducer → decides what happens next&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Nothing changes yet — this only sets up the system.&lt;/p&gt;




&lt;h1&gt;
  
  
  State Begins the Journey
&lt;/h1&gt;

&lt;p&gt;Now imagine state starting 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;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This becomes the single source of truth.&lt;/p&gt;

&lt;p&gt;Every change in the future will create a new version of this structure instead of modifying it directly.&lt;/p&gt;

&lt;p&gt;That’s why React can reliably update the UI — because every update is a fresh object.&lt;/p&gt;




&lt;h1&gt;
  
  
  Dispatch Starts Everything
&lt;/h1&gt;

&lt;p&gt;Now something happens in the UI.&lt;/p&gt;

&lt;p&gt;Instead of changing state directly, a message is sent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;dispatch&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;increment&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;At this point, nothing has changed yet.&lt;/p&gt;

&lt;p&gt;This is just an instruction saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“something happened”.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That instruction now moves to the central decision point.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Decision Point
&lt;/h1&gt;

&lt;p&gt;Everything reaches this function:&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;reducer&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;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;case&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;decrement&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="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nl"&gt;default&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;state&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 break this flow mentally:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;state gives current value&lt;/li&gt;
&lt;li&gt;action tells what happened&lt;/li&gt;
&lt;li&gt;switch chooses the path&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each path creates a new version of state.&lt;/p&gt;

&lt;p&gt;Nothing is modified directly — everything is replaced with a new result.&lt;/p&gt;




&lt;h1&gt;
  
  
  Connecting It All in a Component
&lt;/h1&gt;

&lt;p&gt;Now everything comes together:&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;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This sets the starting point.&lt;/p&gt;

&lt;p&gt;Now the reducer defines how this value will change over 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;function&lt;/span&gt; &lt;span class="nf"&gt;reducer&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;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;case&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;decrement&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="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nl"&gt;default&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;state&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 the component connects 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="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;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useReducer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;reducer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialState&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;h1&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;state&lt;/span&gt;&lt;span class="p"&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;h1&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;dispatch&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;increment&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;button&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;dispatch&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;decrement&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;button&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;Now follow the full loop:&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 → dispatch sends action → reducer receives it → state updates → UI re-renders
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything stays inside one predictable cycle.&lt;/p&gt;




&lt;h1&gt;
  
  
  Actions Carry Intent
&lt;/h1&gt;

&lt;p&gt;An action is always simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;dispatch&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;increment&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;It does not change anything directly.&lt;/p&gt;

&lt;p&gt;It only describes what happened so the reducer can decide what to do.&lt;/p&gt;




&lt;h1&gt;
  
  
  When Data Is Needed
&lt;/h1&gt;

&lt;p&gt;Sometimes actions carry extra information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;dispatch&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;ADD_USER&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&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;Now the reducer uses that data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ADD_USER&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="na"&gt;users&lt;/span&gt;&lt;span class="p"&gt;:&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;users&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&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 the same pattern continues:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;event → action → reducer → new state
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Real Flow — Multi-Step Form
&lt;/h1&gt;

&lt;p&gt;Now this pattern expands into real applications.&lt;/p&gt;

&lt;p&gt;A form usually has multiple connected parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;step tracking&lt;/li&gt;
&lt;li&gt;form data&lt;/li&gt;
&lt;li&gt;validation errors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So everything is grouped together:&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;initialState&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;step&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

  &lt;span class="na"&gt;formData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="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;errors&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 change must respect this structure.&lt;/p&gt;




&lt;h1&gt;
  
  
  Updating Form Fields
&lt;/h1&gt;

&lt;p&gt;Instead of writing separate logic for each input, everything flows through one pattern:&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;reducer&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;action&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;UPDATE_FIELD&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="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="na"&gt;formData&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;state&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;action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;field&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt; &lt;span class="nx"&gt;action&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="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NEXT_STEP&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="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="na"&gt;step&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;step&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="nl"&gt;default&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;state&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 focus on the flow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;existing state is copied&lt;/li&gt;
&lt;li&gt;only one field inside formData changes&lt;/li&gt;
&lt;li&gt;everything else stays intact&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s how structure is preserved.&lt;/p&gt;




&lt;h1&gt;
  
  
  Input Connection
&lt;/h1&gt;

&lt;p&gt;Each input follows the same path:&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;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;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;dispatch&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;UPDATE_FIELD&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;field&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="na"&gt;value&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now every keystroke follows the same cycle:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;user input → dispatch → reducer → state update → UI refresh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No duplication. No scattered logic.&lt;/p&gt;




&lt;h1&gt;
  
  
  When It Makes Sense
&lt;/h1&gt;

&lt;p&gt;This approach becomes useful when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;state starts interacting with other state&lt;/li&gt;
&lt;li&gt;updates depend on previous values&lt;/li&gt;
&lt;li&gt;logic becomes harder to manage&lt;/li&gt;
&lt;li&gt;component starts growing fast&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  When It Doesn’t
&lt;/h1&gt;

&lt;p&gt;If state is simple and isolated:&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setOpen&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;there is no need for extra structure.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Core Idea
&lt;/h1&gt;

&lt;p&gt;Simple state changes are independent.&lt;/p&gt;

&lt;p&gt;Reducer-based state changes are structured flows.&lt;/p&gt;

&lt;p&gt;That difference becomes important as applications scale.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why Developers Prefer It
&lt;/h1&gt;

&lt;p&gt;Because it naturally brings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;predictable updates&lt;/li&gt;
&lt;li&gt;centralized control&lt;/li&gt;
&lt;li&gt;scalable structure&lt;/li&gt;
&lt;li&gt;clean separation of logic&lt;/li&gt;
&lt;li&gt;easier debugging&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Redux Connection
&lt;/h1&gt;

&lt;p&gt;This same pattern evolves into Redux:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;actions → reducers → dispatch → store updates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So understanding this now builds a strong foundation for larger systems later.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;At this stage, React is no longer just about writing UI.&lt;/p&gt;

&lt;p&gt;It becomes about designing how data moves.&lt;/p&gt;

&lt;p&gt;Because the real difference between simple apps and scalable apps is not syntax…&lt;/p&gt;

&lt;p&gt;It’s structure.&lt;/p&gt;

&lt;p&gt;And useReducer introduces that structure.&lt;/p&gt;

&lt;p&gt;Instead of asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“How do I change this value?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You start asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“How should this value change over time?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That shift is what separates writing code from designing applications.&lt;/p&gt;




&lt;h1&gt;
  
  
  What to Remember
&lt;/h1&gt;

&lt;p&gt;When state starts feeling scattered:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bring it into one flow.&lt;/li&gt;
&lt;li&gt;Let actions describe events.&lt;/li&gt;
&lt;li&gt;Let reducers decide outcomes.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That single mindset shift is what levels up your React thinking.&lt;/p&gt;




&lt;h1&gt;
  
  
  Next Episode
&lt;/h1&gt;

&lt;p&gt;In the next episode of &lt;strong&gt;“Let’s Master React Hooks Together”&lt;/strong&gt;, we’ll explore advanced React patterns that build on this foundation and take your applications closer to production-level architecture.&lt;/p&gt;

&lt;p&gt;Stay consistent.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>learning</category>
    </item>
    <item>
      <title>What Building a Quiz Web App Taught Me About React</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Mon, 11 May 2026 15:30:27 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/what-building-a-quiz-web-app-taught-me-about-react-fi1</link>
      <guid>https://dev.to/kathirvel-s/what-building-a-quiz-web-app-taught-me-about-react-fi1</guid>
      <description>&lt;h1&gt;
  
  
  From Confusion to Confidence — Building My Quiz Web App with React
&lt;/h1&gt;

&lt;p&gt;As part of my React learning journey at Payilagam, this Quiz Web App project was guided by Vijaya Ragavan sir.&lt;br&gt;
This project helped me understand how real React applications work practically instead of only learning concepts theoretically.&lt;/p&gt;

&lt;p&gt;What started as a simple quiz application slowly became one of the most exciting and confidence-building projects in my learning journey &lt;/p&gt;


&lt;h1&gt;
  
  
  Live Project Link
&lt;/h1&gt;

&lt;p&gt;👉 &lt;strong&gt;Try My Quiz Web App Here:&lt;/strong&gt;&lt;br&gt;
[&lt;a href="https://react-projects-rjy7.vercel.app/" rel="noopener noreferrer"&gt;https://react-projects-rjy7.vercel.app/&lt;/a&gt;]&lt;/p&gt;


&lt;h1&gt;
  
  
  The Idea Behind the Project
&lt;/h1&gt;

&lt;p&gt;While learning React, I didn’t want to just watch tutorials and memorize syntax.&lt;/p&gt;

&lt;p&gt;I wanted to build something interactive where I could actually apply:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React Hooks&lt;/li&gt;
&lt;li&gt;Routing&lt;/li&gt;
&lt;li&gt;State Management&lt;/li&gt;
&lt;li&gt;Dynamic Rendering&lt;/li&gt;
&lt;li&gt;User Interaction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s when I started building this Quiz Web App &lt;/p&gt;

&lt;p&gt;The application flow is simple and user-friendly:&lt;/p&gt;

&lt;p&gt;✅ User enters their name&lt;br&gt;
✅ Quiz starts&lt;br&gt;
✅ Questions appear one by one&lt;br&gt;
✅ User selects answers&lt;br&gt;
✅ Final score gets displayed&lt;br&gt;
✅ User can restart the quiz again&lt;/p&gt;

&lt;p&gt;Even though the concept sounds simple, building it taught me many important frontend development concepts.&lt;/p&gt;


&lt;h1&gt;
  
  
  React Concepts I Used
&lt;/h1&gt;

&lt;p&gt;This single project helped me work with several important React concepts like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;useState&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useEffect&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useContext&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useRef&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;useNavigate&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;BrowserRouter&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Routing &amp;amp; Navigation&lt;/li&gt;
&lt;li&gt;Protected Routes&lt;/li&gt;
&lt;li&gt;JSON Data Handling&lt;/li&gt;
&lt;li&gt;Conditional Rendering&lt;/li&gt;
&lt;li&gt;Event Handling&lt;/li&gt;
&lt;li&gt;Dynamic UI Rendering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of learning these concepts separately,&lt;br&gt;
this project helped me understand how everything connects together inside a real application.&lt;/p&gt;


&lt;h1&gt;
  
  
  Setting Up Routing Using BrowserRouter
&lt;/h1&gt;

&lt;p&gt;The first thing I worked on was setting up routing for the application.&lt;/p&gt;

&lt;p&gt;I used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;BrowserRouter&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Routes&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Route&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Navigate&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;to create separate pages for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User Page&lt;/li&gt;
&lt;li&gt;Quiz Page&lt;/li&gt;
&lt;li&gt;Result Page
&lt;/li&gt;
&lt;/ul&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;BrowserRouter&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;Routes&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;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'/'&lt;/span&gt; &lt;span class="na"&gt;element&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;lt;&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt; &lt;span class="p"&gt;/&amp;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;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'/quiz'&lt;/span&gt; &lt;span class="na"&gt;element&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;lt;&lt;/span&gt;&lt;span class="nc"&gt;Quiz&lt;/span&gt; &lt;span class="p"&gt;/&amp;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;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'/result'&lt;/span&gt; &lt;span class="na"&gt;element&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;lt;&lt;/span&gt;&lt;span class="nc"&gt;Result&lt;/span&gt; &lt;span class="p"&gt;/&amp;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;Routes&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;BrowserRouter&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;This made the application feel like a real website instead of a single static page.&lt;/p&gt;

&lt;p&gt;When page navigation started working smoothly without reloading the browser, it honestly felt amazing&lt;/p&gt;


&lt;h1&gt;
  
  
  Designing the User Page
&lt;/h1&gt;

&lt;p&gt;The User page is where the quiz experience begins.&lt;/p&gt;

&lt;p&gt;I created a simple and clean interface with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Input field&lt;/li&gt;
&lt;li&gt;Start Quiz button&lt;/li&gt;
&lt;li&gt;Auto-focus functionality&lt;/li&gt;
&lt;li&gt;Name formatting logic&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One small feature I liked was automatically focusing the input box using &lt;code&gt;useRef&lt;/code&gt; and &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;userRef&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="nf"&gt;focus&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 may look like a small thing,&lt;br&gt;
but it improves user experience and gives a professional feel to the application.&lt;/p&gt;


&lt;h1&gt;
  
  
  Name Formatting Logic
&lt;/h1&gt;

&lt;p&gt;I also added logic to automatically format the entered user name properly.&lt;/p&gt;

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

&lt;p&gt;❌ &lt;code&gt;vIjAy rAgAvAn&lt;/code&gt;&lt;br&gt;
✅ &lt;code&gt;Vijay Ragavan&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="nx"&gt;formatted&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="nx"&gt;value&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&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;toLowerCase&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="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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;While writing this logic, I understood how JavaScript string methods can be used effectively inside React applications.&lt;/p&gt;




&lt;h1&gt;
  
  
  Understanding useState Through Real Application Logic
&lt;/h1&gt;

&lt;p&gt;This project helped me understand the actual purpose of &lt;code&gt;useState&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I used states for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Current question&lt;/li&gt;
&lt;li&gt;Selected option&lt;/li&gt;
&lt;li&gt;User score&lt;/li&gt;
&lt;li&gt;User name&lt;/li&gt;
&lt;li&gt;Route access permission
&lt;/li&gt;
&lt;/ul&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;crntQz&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCrntQz&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;optChosen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setOptChosen&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;Whenever the state changes,&lt;br&gt;
React automatically updates the UI.&lt;/p&gt;

&lt;p&gt;That real-time re-rendering experience made React much easier to understand for me.&lt;/p&gt;


&lt;h1&gt;
  
  
  useContext — The Most Important Concept in This Project
&lt;/h1&gt;

&lt;p&gt;Among all the hooks I used,&lt;br&gt;
&lt;code&gt;useContext&lt;/code&gt; became the most important one in this project.&lt;/p&gt;

&lt;p&gt;Instead of passing props manually through multiple components,&lt;br&gt;
I created a global 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;QuizData&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;Using this context, I shared:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User name&lt;/li&gt;
&lt;li&gt;Score&lt;/li&gt;
&lt;li&gt;Permission state&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;across all pages easily.&lt;/p&gt;

&lt;p&gt;This made the code:&lt;br&gt;
✅ Cleaner&lt;br&gt;
✅ Easier to manage&lt;br&gt;
✅ More organized&lt;/p&gt;

&lt;p&gt;Before this project, &lt;code&gt;useContext&lt;/code&gt; felt confusing.&lt;br&gt;
But implementing it practically made the concept much clearer.&lt;/p&gt;


&lt;h1&gt;
  
  
  Protected Route Logic
&lt;/h1&gt;

&lt;p&gt;One feature that made the application feel more realistic was route protection.&lt;/p&gt;

&lt;p&gt;I didn’t want users to directly access the &lt;code&gt;/quiz&lt;/code&gt; page without entering their name first.&lt;/p&gt;

&lt;p&gt;So I added this condition:&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;Route&lt;/span&gt;
  &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'/quiz'&lt;/span&gt;
  &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;userPer&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;Quiz&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;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Navigate&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&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="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the user tries to open the quiz page directly,&lt;br&gt;
they are automatically redirected back to the home page.&lt;/p&gt;

&lt;p&gt;This feature gave the project a more professional feel.&lt;/p&gt;


&lt;h1&gt;
  
  
  Building the Main Quiz Logic
&lt;/h1&gt;

&lt;p&gt;This was the core part of the project.&lt;/p&gt;

&lt;p&gt;I implemented:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Question navigation&lt;/li&gt;
&lt;li&gt;Option selection&lt;/li&gt;
&lt;li&gt;Next button functionality&lt;/li&gt;
&lt;li&gt;Finish button logic&lt;/li&gt;
&lt;li&gt;Score calculation&lt;/li&gt;
&lt;li&gt;Dynamic rendering&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Questions were stored inside a JSON file:&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;questions&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;../assets/questions.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This helped me understand how applications handle external structured data.&lt;/p&gt;




&lt;h1&gt;
  
  
  Dynamic Rendering Using map()
&lt;/h1&gt;

&lt;p&gt;Instead of manually creating option buttons,&lt;br&gt;
I dynamically rendered them using &lt;code&gt;.map()&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;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;A&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;B&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;C&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;D&lt;/span&gt;&lt;span class="dl"&gt;"&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;opt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&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;index&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;questions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;crntQz&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="s2"&gt;`option&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;opt&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;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;This was one of the moments where React’s power became very clear to me.&lt;/p&gt;

&lt;p&gt;The code became shorter, cleaner, and easier to maintain.&lt;/p&gt;




&lt;h1&gt;
  
  
  Score Calculation Logic
&lt;/h1&gt;

&lt;p&gt;The application checks whether the selected answer matches the correct answer.&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;optChosen&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;questions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;crntQz&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;answer&lt;/span&gt; &lt;span class="p"&gt;){&lt;/span&gt;
   &lt;span class="nf"&gt;setScore&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each correct answer increases the score.&lt;/p&gt;

&lt;p&gt;Simple logic…&lt;br&gt;
but implementing it successfully gave me a lot of confidence as a beginner developer.&lt;/p&gt;




&lt;h1&gt;
  
  
  Result Page
&lt;/h1&gt;

&lt;p&gt;After completing the quiz,&lt;br&gt;
users are redirected to the Result page.&lt;/p&gt;

&lt;p&gt;The page displays:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User name&lt;/li&gt;
&lt;li&gt;Final score&lt;/li&gt;
&lt;li&gt;Restart button
&lt;/li&gt;
&lt;/ul&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;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;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;, Your Score is &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; / 5 &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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also added a “Start Quiz Again” button to improve interaction and make the app reusable.&lt;/p&gt;




&lt;h1&gt;
  
  
  Challenges I Faced
&lt;/h1&gt;

&lt;p&gt;Building this project was exciting,&lt;br&gt;
but there were definitely challenging moments too.&lt;/p&gt;

&lt;p&gt;Some issues I faced:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;State update confusion&lt;/li&gt;
&lt;li&gt;Route navigation problems&lt;/li&gt;
&lt;li&gt;Score calculation bugs&lt;/li&gt;
&lt;li&gt;Option reset issues&lt;/li&gt;
&lt;li&gt;Context-related mistakes&lt;/li&gt;
&lt;li&gt;Conditional rendering confusion&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sometimes a very small bug took a long time to solve&lt;/p&gt;

&lt;p&gt;But those debugging moments improved my logic-building and problem-solving skills a lot.&lt;/p&gt;




&lt;h1&gt;
  
  
  What This Project Taught Me
&lt;/h1&gt;

&lt;p&gt;This project taught me much more than just React syntax.&lt;/p&gt;

&lt;p&gt;It helped me understand:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How React applications are structured&lt;/li&gt;
&lt;li&gt;How hooks work practically&lt;/li&gt;
&lt;li&gt;How components communicate&lt;/li&gt;
&lt;li&gt;How state controls UI updates&lt;/li&gt;
&lt;li&gt;How routing improves user experience&lt;/li&gt;
&lt;li&gt;How frontend logic is built step by step&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most importantly,&lt;br&gt;
it taught me that real learning happens while building projects.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;This Quiz Web App may be a beginner-level project,&lt;br&gt;
but for me, it represents a huge learning milestone.&lt;/p&gt;

&lt;p&gt;This was the project where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React started making sense&lt;/li&gt;
&lt;li&gt;Hooks became easier to understand&lt;/li&gt;
&lt;li&gt;My coding confidence started growing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And honestly…&lt;/p&gt;

&lt;p&gt;Seeing my own application work successfully from start to finish felt incredibly satisfying &lt;/p&gt;

&lt;p&gt;If you’re also learning React or web development,&lt;br&gt;
don’t wait until you feel “perfect.”&lt;/p&gt;

&lt;p&gt;Start building.&lt;br&gt;
Experiment.&lt;br&gt;
Debug.&lt;br&gt;
Improve.&lt;/p&gt;

&lt;p&gt;Because every project teaches something new &lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The Hidden Reason Python Became the Face of AI</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Sun, 10 May 2026 08:37:14 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/the-hidden-reason-python-became-the-face-of-ai-39j6</link>
      <guid>https://dev.to/kathirvel-s/the-hidden-reason-python-became-the-face-of-ai-39j6</guid>
      <description>&lt;h1&gt;
  
  
  Why Python Is the #1 Language for AI
&lt;/h1&gt;

&lt;p&gt;Welcome back to &lt;strong&gt;Sunday Source – I Break It, Then Explain It&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;This is &lt;strong&gt;Episode #2&lt;/strong&gt;, and today we’re talking about something almost impossible to ignore in tech right now:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Why does almost every AI tool, tutorial, and startup somehow end up using Python?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Seriously.&lt;/p&gt;

&lt;p&gt;Chatbots? Python.&lt;br&gt;&lt;br&gt;
Machine learning? Python.&lt;br&gt;&lt;br&gt;
AI automation? Again… Python.&lt;/p&gt;

&lt;p&gt;At this point, it almost feels illegal to build AI without it 😅&lt;/p&gt;

&lt;p&gt;But here’s the real question:&lt;/p&gt;

&lt;p&gt;Why Python?&lt;/p&gt;

&lt;p&gt;Why not Java?&lt;br&gt;&lt;br&gt;
Why not C++?&lt;br&gt;&lt;br&gt;
Why not JavaScript?&lt;/p&gt;

&lt;p&gt;Is Python actually the most powerful language for artificial intelligence… or is it just the most popular?&lt;/p&gt;

&lt;p&gt;In this episode, I’ll break down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;why Python became the default language for AI,&lt;/li&gt;
&lt;li&gt;what makes developers love it,&lt;/li&gt;
&lt;li&gt;and whether Python truly deserves the crown.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And don’t worry — no boring textbook explanations here.&lt;/p&gt;

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




&lt;h1&gt;
  
  
  Why AI Needed a Language Like Python
&lt;/h1&gt;

&lt;p&gt;Artificial intelligence is full of heavy concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Math&lt;/li&gt;
&lt;li&gt;Data&lt;/li&gt;
&lt;li&gt;Algorithms&lt;/li&gt;
&lt;li&gt;Neural networks&lt;/li&gt;
&lt;li&gt;Endless experiments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now imagine doing all that in a language with complicated syntax.&lt;/p&gt;

&lt;p&gt;Sounds painful, right?&lt;/p&gt;

&lt;p&gt;AI developers need to test ideas quickly. They don’t want to spend hours fixing semicolons or writing 20 extra lines just to print something on the screen.&lt;/p&gt;

&lt;p&gt;Python made AI development feel simpler.&lt;/p&gt;

&lt;p&gt;Here’s a tiny example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Python:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello AI&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Java:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Main&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello AI"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Be honest…&lt;/p&gt;

&lt;p&gt;Which one feels less stressful?&lt;/p&gt;

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

&lt;p&gt;That simplicity matters a LOT in artificial intelligence.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Biggest Reasons Python Dominates AI
&lt;/h1&gt;

&lt;h2&gt;
  
  
  1. Python Is Easy to Read
&lt;/h2&gt;

&lt;p&gt;Python almost looks like normal English.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Beginners learn faster&lt;/li&gt;
&lt;li&gt;Teams collaborate better&lt;/li&gt;
&lt;li&gt;Bugs become easier to find&lt;/li&gt;
&lt;li&gt;Developers focus more on AI logic instead of syntax&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And in AI projects, clarity is everything.&lt;/p&gt;

&lt;p&gt;Because trust me — debugging a neural network is already confusing enough.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Python Has Powerful AI Libraries
&lt;/h2&gt;

&lt;p&gt;This is probably Python’s biggest superpower.&lt;/p&gt;

&lt;p&gt;Instead of building everything from scratch, developers can use powerful libraries.&lt;/p&gt;

&lt;p&gt;Some famous ones are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TensorFlow&lt;/li&gt;
&lt;li&gt;PyTorch&lt;/li&gt;
&lt;li&gt;NumPy&lt;/li&gt;
&lt;li&gt;Pandas&lt;/li&gt;
&lt;li&gt;Scikit-learn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These libraries save thousands of hours of work.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;NumPy&lt;/strong&gt; handles fast mathematical calculations&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pandas&lt;/strong&gt; works with datasets&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TensorFlow&lt;/strong&gt; helps train deep learning models&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PyTorch&lt;/strong&gt; is loved by AI researchers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without these tools, AI development would be much slower.&lt;/p&gt;

&lt;p&gt;Imagine building a car by first inventing the wheel every single time.&lt;/p&gt;

&lt;p&gt;That’s life without libraries.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Python Is Perfect for Beginners
&lt;/h2&gt;

&lt;p&gt;Let’s be real.&lt;/p&gt;

&lt;p&gt;AI already feels intimidating.&lt;/p&gt;

&lt;p&gt;There are terms like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transformers&lt;/li&gt;
&lt;li&gt;Neural networks&lt;/li&gt;
&lt;li&gt;Backpropagation&lt;/li&gt;
&lt;li&gt;Gradient descent&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now imagine learning all that while also fighting a difficult programming language.&lt;/p&gt;

&lt;p&gt;Python reduces that learning pressure.&lt;/p&gt;

&lt;p&gt;That’s why most universities and online courses teach Python for AI first.&lt;/p&gt;

&lt;p&gt;It lets beginners focus on understanding AI instead of struggling with syntax.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Fast Experimentation Matters in AI
&lt;/h2&gt;

&lt;p&gt;AI is not just coding.&lt;/p&gt;

&lt;p&gt;It’s testing ideas constantly.&lt;/p&gt;

&lt;p&gt;Sometimes developers train models for hours… only to realize the idea doesn’t work.&lt;/p&gt;

&lt;p&gt;Painful? Absolutely.&lt;/p&gt;

&lt;p&gt;That’s why fast experimentation matters.&lt;/p&gt;

&lt;p&gt;Python helps developers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write code quickly&lt;/li&gt;
&lt;li&gt;Test models faster&lt;/li&gt;
&lt;li&gt;Change ideas easily&lt;/li&gt;
&lt;li&gt;Build prototypes rapidly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is one reason startups LOVE Python.&lt;/p&gt;

&lt;p&gt;Speed of development often matters more than raw performance.&lt;/p&gt;




&lt;h1&gt;
  
  
  Quick Summary
&lt;/h1&gt;

&lt;p&gt;Why is Python the best language for AI?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple syntax&lt;/li&gt;
&lt;li&gt;Massive AI libraries&lt;/li&gt;
&lt;li&gt;Beginner friendly&lt;/li&gt;
&lt;li&gt;Huge community&lt;/li&gt;
&lt;li&gt;Faster experimentation&lt;/li&gt;
&lt;li&gt;Strong machine learning ecosystem&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  Is Python Actually Fast?
&lt;/h1&gt;

&lt;p&gt;Here’s where things get interesting.&lt;/p&gt;

&lt;p&gt;Python itself is actually slower than languages like C++.&lt;/p&gt;

&lt;p&gt;Wait… what?&lt;/p&gt;

&lt;p&gt;Then why use it for AI?&lt;/p&gt;

&lt;p&gt;Because most AI libraries are secretly powered by super-fast languages underneath.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TensorFlow uses optimized C++ code&lt;/li&gt;
&lt;li&gt;PyTorch uses CUDA for GPU acceleration&lt;/li&gt;
&lt;li&gt;NumPy runs highly optimized computations internally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So while developers write simple Python code…&lt;/p&gt;

&lt;p&gt;The heavy lifting happens behind the scenes using GPUs and faster low-level systems.&lt;/p&gt;

&lt;p&gt;Sneaky, right?&lt;/p&gt;




&lt;h1&gt;
  
  
  Python vs Other Languages for AI
&lt;/h1&gt;

&lt;p&gt;Let’s compare quickly.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Good For&lt;/th&gt;
&lt;th&gt;Problem&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Python&lt;/td&gt;
&lt;td&gt;AI, ML, beginners&lt;/td&gt;
&lt;td&gt;Slightly slower&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Java&lt;/td&gt;
&lt;td&gt;Enterprise systems&lt;/td&gt;
&lt;td&gt;More complex syntax&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;C++&lt;/td&gt;
&lt;td&gt;High performance&lt;/td&gt;
&lt;td&gt;Harder to learn&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JavaScript&lt;/td&gt;
&lt;td&gt;Web AI apps&lt;/td&gt;
&lt;td&gt;Smaller AI ecosystem&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So does this mean other languages are bad?&lt;/p&gt;

&lt;p&gt;Not at all.&lt;/p&gt;

&lt;p&gt;C++ is amazing for performance-heavy systems.&lt;/p&gt;

&lt;p&gt;JavaScript works great for browser AI.&lt;/p&gt;

&lt;p&gt;But Python gives the best balance between:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;simplicity&lt;/li&gt;
&lt;li&gt;power&lt;/li&gt;
&lt;li&gt;speed&lt;/li&gt;
&lt;li&gt;community support&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that balance changed everything.&lt;/p&gt;




&lt;h1&gt;
  
  
  Real Companies Using Python for AI
&lt;/h1&gt;

&lt;p&gt;Still wondering if Python in artificial intelligence is truly a big deal?&lt;/p&gt;

&lt;p&gt;Some of the world’s biggest companies use it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Google
&lt;/h3&gt;

&lt;p&gt;Uses Python in machine learning and AI research.&lt;/p&gt;

&lt;h3&gt;
  
  
  OpenAI
&lt;/h3&gt;

&lt;p&gt;Python plays a major role in AI model development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Netflix
&lt;/h3&gt;

&lt;p&gt;Uses Python for recommendation systems and data analysis.&lt;/p&gt;

&lt;p&gt;And honestly…&lt;/p&gt;

&lt;p&gt;When companies handling billions of users trust Python for AI, that says a lot.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Real Secret Behind Python’s Success
&lt;/h1&gt;

&lt;p&gt;Here’s something people don’t talk about enough.&lt;/p&gt;

&lt;p&gt;Python removes friction.&lt;/p&gt;

&lt;p&gt;It helps developers turn ideas into experiments quickly.&lt;/p&gt;

&lt;p&gt;That changes creativity.&lt;/p&gt;

&lt;p&gt;Because when coding feels easier, people build more things.&lt;/p&gt;

&lt;p&gt;And AI grows through experimentation.&lt;/p&gt;

&lt;p&gt;Maybe Python didn’t win because it was the fastest language.&lt;/p&gt;

&lt;p&gt;Maybe it won because it made AI feel accessible to everyone.&lt;/p&gt;

&lt;p&gt;That’s powerful.&lt;/p&gt;




&lt;h1&gt;
  
  
  Before You Scroll away
&lt;/h1&gt;

&lt;p&gt;Python became the #1 language for AI because it made complicated things feel simpler.&lt;/p&gt;

&lt;p&gt;It gave developers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;easy syntax&lt;/li&gt;
&lt;li&gt;powerful tools&lt;/li&gt;
&lt;li&gt;faster workflows&lt;/li&gt;
&lt;li&gt;and a huge community ready to help.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And honestly, in a field as complex as artificial intelligence, simplicity becomes a superpower.&lt;/p&gt;

&lt;p&gt;Maybe Python didn’t dominate AI because it was the fastest language.&lt;/p&gt;

&lt;p&gt;Maybe it won because it removed friction between human ideas and machine learning.&lt;/p&gt;

&lt;p&gt;And that changed everything.&lt;/p&gt;

&lt;p&gt;That’s it for &lt;strong&gt;Episode #2 of Sunday Source – I Break It, Then Explain It&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you enjoyed this breakdown Then the this series doing it's work perfectly &lt;/p&gt;

&lt;p&gt;See you next Sunday for another Sunday Source episode. &lt;/p&gt;

</description>
      <category>python</category>
      <category>ai</category>
      <category>productivity</category>
      <category>sundaysource</category>
    </item>
    <item>
      <title>The Smart Way to Share State —Master useContext in React</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Thu, 07 May 2026 13:20:40 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/the-smart-way-to-share-state-master-usecontext-in-react-3ehe</link>
      <guid>https://dev.to/kathirvel-s/the-smart-way-to-share-state-master-usecontext-in-react-3ehe</guid>
      <description>&lt;h2&gt;
  
  
  The Prop Drilling Problem Every React Developer Hits
&lt;/h2&gt;

&lt;p&gt;Welcome back to &lt;strong&gt;Let’s Master React Hooks Together&lt;/strong&gt; — the series where we learn React Hooks the practical way, like real-world developers actually use them.&lt;/p&gt;

&lt;p&gt;In the previous episodes, we explored hooks like &lt;code&gt;useState&lt;/code&gt;, &lt;code&gt;useEffect&lt;/code&gt; and &lt;code&gt;useNavigate&lt;/code&gt; . But now we’re entering a stage where React apps start becoming &lt;em&gt;real applications&lt;/em&gt; — with shared state, nested components, themes, authentication, and global UI behavior.&lt;/p&gt;

&lt;p&gt;And that’s exactly where developers hit one frustrating problem:&lt;/p&gt;

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

&lt;p&gt;You create a piece of state in a parent component, but suddenly you’re passing it through 4 or 5 layers of components just so one deeply nested child can use it.&lt;/p&gt;

&lt;p&gt;Your component tree starts looking 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 → Layout → Header → Navbar → Button
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And somewhere deep inside that tree, a button just needs the current theme or logged-in user.&lt;/p&gt;

&lt;p&gt;The result?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;messy props&lt;/li&gt;
&lt;li&gt;unnecessary component coupling&lt;/li&gt;
&lt;li&gt;harder maintenance&lt;/li&gt;
&lt;li&gt;painful refactoring&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React introduced the &lt;strong&gt;Context API&lt;/strong&gt; to solve this problem.&lt;/p&gt;

&lt;p&gt;And later, hooks made it dramatically cleaner with &lt;code&gt;useContext&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In this episode, we’ll learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;what &lt;code&gt;useContext&lt;/code&gt; is&lt;/li&gt;
&lt;li&gt;why React introduced it&lt;/li&gt;
&lt;li&gt;how it works mentally&lt;/li&gt;
&lt;li&gt;when to use it&lt;/li&gt;
&lt;li&gt;when NOT to use it&lt;/li&gt;
&lt;li&gt;performance pitfalls developers often miss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s master it properly.&lt;/p&gt;




&lt;h1&gt;
  
  
  The Problem: Prop Drilling in React
&lt;/h1&gt;

&lt;p&gt;Imagine you want to pass &lt;code&gt;theme&lt;/code&gt; and &lt;code&gt;user&lt;/code&gt; data to a deeply nested 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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Layout&lt;/span&gt; &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"dark"&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;user&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Layout&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;theme&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;span class="k"&gt;return&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="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;theme&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;user&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="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="nx"&gt;theme&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;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Navbar&lt;/span&gt; &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;theme&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;user&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Navbar&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;theme&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;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="na"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;theme&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;user&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the issue?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Layout&lt;/code&gt;, &lt;code&gt;Header&lt;/code&gt;, and &lt;code&gt;Navbar&lt;/code&gt; may not even care about &lt;code&gt;theme&lt;/code&gt; or &lt;code&gt;user&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;They’re just forwarding props downward.&lt;/p&gt;

&lt;p&gt;This creates unnecessary complexity:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;components become harder to read&lt;/li&gt;
&lt;li&gt;props explode over time&lt;/li&gt;
&lt;li&gt;refactoring becomes risky&lt;/li&gt;
&lt;li&gt;maintenance gets annoying&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mentally, it 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;App → Layout → Header → Navbar → Button → Theme
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As applications grow, this pattern becomes difficult to manage.&lt;/p&gt;

&lt;p&gt;React needed a cleaner way for components to access shared data directly.&lt;/p&gt;

&lt;p&gt;That’s where Context comes in.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is Context API?
&lt;/h1&gt;

&lt;p&gt;The &lt;strong&gt;Context API&lt;/strong&gt; is React’s built-in shared state mechanism.&lt;/p&gt;

&lt;p&gt;It allows components to access common data without manually passing props through every level.&lt;/p&gt;

&lt;p&gt;Think of it like a &lt;strong&gt;WiFi router&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Any device inside the network can access the internet without needing a direct cable connection to the source.&lt;/p&gt;

&lt;p&gt;Similarly, components inside a Context Provider can access shared data directly.&lt;/p&gt;

&lt;p&gt;React Context mainly consists of 3 parts:&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create Context
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ThemeContext&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;h2&gt;
  
  
  2. Provider
&lt;/h2&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;ThemeContext&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="nx"&gt;theme&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;h2&gt;
  
  
  3. Consumer (&lt;code&gt;useContext&lt;/code&gt;)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;theme&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;ThemeContext&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 the core idea.&lt;/p&gt;

&lt;p&gt;Simple concept. Massive improvement in component architecture.&lt;/p&gt;




&lt;h1&gt;
  
  
  What is &lt;code&gt;useContext&lt;/code&gt;?
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;useContext&lt;/code&gt; is a React Hook that lets a component read data from a 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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&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;MyContext&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In simple words:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Give me the nearest value from this context.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before hooks existed, developers used &lt;code&gt;Context.Consumer&lt;/code&gt;, which quickly became deeply nested and difficult to read.&lt;/p&gt;

&lt;p&gt;Hooks made Context usage much cleaner and more natural.&lt;/p&gt;

&lt;h2&gt;
  
  
  Slightly Technical Understanding
&lt;/h2&gt;

&lt;p&gt;When React renders a component using &lt;code&gt;useContext&lt;/code&gt;, it searches upward through the component tree for the nearest matching Provider.&lt;/p&gt;

&lt;p&gt;If the Provider value changes, React re-renders the components consuming that context.&lt;/p&gt;

&lt;p&gt;That’s the main mental model.&lt;/p&gt;




&lt;h1&gt;
  
  
  Real Example: Theme Switching
&lt;/h1&gt;

&lt;p&gt;Let’s build a simple dark/light theme system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Context
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="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;ThemeContext&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;h2&gt;
  
  
  Create Provider
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ThemeProvider&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;theme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTheme&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="s2"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;toggleTheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setTheme&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;=&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;light&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;dark&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;light&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="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;ThemeContext&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;theme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toggleTheme&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;ThemeContext&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;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Consume Context
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useContext&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;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ThemeContext&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;./ThemeContext&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Button&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;theme&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;toggleTheme&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;ThemeContext&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;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;toggleTheme&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      Current theme: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;theme&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;button&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;Now any component inside &lt;code&gt;ThemeProvider&lt;/code&gt; can directly access the theme.&lt;/p&gt;

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

&lt;p&gt;No unnecessary intermediary props.&lt;/p&gt;

&lt;p&gt;Cleaner architecture.&lt;/p&gt;




&lt;h1&gt;
  
  
  How &lt;code&gt;useContext&lt;/code&gt; Works (Mental Model)
&lt;/h1&gt;

&lt;p&gt;Here’s the simplest mental model:&lt;/p&gt;

&lt;p&gt;When React sees 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;useContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ThemeContext&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;it walks upward through the component tree searching for:&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;ThemeContext&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;The &lt;strong&gt;nearest provider wins.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of it like searching for the nearest WiFi signal.&lt;/p&gt;

&lt;p&gt;If the Provider value changes:&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;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;newValue&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-renders components consuming that context.&lt;/p&gt;

&lt;p&gt;That re-render behavior is important for performance.&lt;/p&gt;




&lt;h1&gt;
  
  
  When to Use &lt;code&gt;useContext&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;useContext&lt;/code&gt; works best for &lt;strong&gt;shared application-wide state.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Great use cases include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;theme systems&lt;/li&gt;
&lt;li&gt;authenticated user data&lt;/li&gt;
&lt;li&gt;language switching&lt;/li&gt;
&lt;li&gt;sidebar visibility&lt;/li&gt;
&lt;li&gt;app settings&lt;/li&gt;
&lt;li&gt;cart information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A simple rule:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If many distant components need the same data, Context is usually a good fit.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  When NOT to Use &lt;code&gt;useContext&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;This is where many developers misuse Context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid Frequently Changing State
&lt;/h2&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;typing inputs&lt;/li&gt;
&lt;li&gt;mouse movement&lt;/li&gt;
&lt;li&gt;animations&lt;/li&gt;
&lt;li&gt;rapidly updating values&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because every context update can trigger many component re-renders.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid Replacing Local State
&lt;/h2&gt;

&lt;p&gt;If only one component needs the state, &lt;code&gt;useState&lt;/code&gt; is usually better.&lt;/p&gt;

&lt;p&gt;Not everything belongs in global state.&lt;/p&gt;

&lt;p&gt;Overusing Context creates bloated architectures that become difficult to maintain.&lt;/p&gt;




&lt;h1&gt;
  
  
  Performance Concerns (Important)
&lt;/h1&gt;

&lt;p&gt;Here’s a very common mistake:&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;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;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="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;Why is this problematic?&lt;/p&gt;

&lt;p&gt;Because a new object is created on every render.&lt;/p&gt;

&lt;p&gt;React compares references, not deep values:&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="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;So all consuming components re-render.&lt;/p&gt;

&lt;p&gt;Even if &lt;code&gt;user&lt;/code&gt; didn’t actually change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Better Approach
&lt;/h2&gt;

&lt;p&gt;Memoize the value:&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;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useMemo&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another important optimization:&lt;/p&gt;

&lt;h2&gt;
  
  
  Split Contexts by Concern
&lt;/h2&gt;

&lt;p&gt;Instead of one massive global context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AppContext
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;prefer smaller focused contexts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ThemeContext
AuthContext
LanguageContext
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reduces unnecessary re-renders and improves maintainability.&lt;/p&gt;




&lt;h1&gt;
  
  
  Best Practices
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Keep Context Small&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Focused contexts are easier to manage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Split by Responsibility&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Separate auth, theme, language, cart, etc.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Avoid Giant Global Contexts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Large contexts become difficult to debug and optimize.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep Provider Values Stable&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Memoize objects and functions when necessary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Custom Hooks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cleaner 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;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useTheme&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 repeatedly calling &lt;code&gt;useContext&lt;/code&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  Real-World Examples
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Authentication System&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Store logged-in user data globally so navbar, dashboard, and profile pages can access it instantly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Theme System&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dark/light mode is one of the best examples of Context usage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Language Switcher&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Allow the entire application to switch languages consistently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shopping Cart&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;E-commerce apps often share cart count and cart items across many components.&lt;/p&gt;




&lt;h2&gt;
  
  
  Interview Questions (Quick Revision)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is &lt;code&gt;useContext&lt;/code&gt;?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A hook that allows components to consume values from React Context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What problem does it solve?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Prop drilling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does &lt;code&gt;useContext&lt;/code&gt; replace Redux?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. Context helps with shared state, but Redux handles more advanced global state patterns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do consumers re-render?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because the Provider value changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When should you avoid Context?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For fast-changing or highly local component state.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What does “nearest provider wins” mean?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React uses the closest matching Provider above the component in the tree.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Summary
&lt;/h1&gt;

&lt;p&gt;In Episode 5 of &lt;strong&gt;Let’s Master React Hooks Together&lt;/strong&gt;, we learned that &lt;code&gt;useContext&lt;/code&gt; exists to solve one major React problem:&lt;/p&gt;

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

&lt;p&gt;It allows components to access shared state directly without passing props through every layer.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;themes&lt;/li&gt;
&lt;li&gt;authentication&lt;/li&gt;
&lt;li&gt;language settings&lt;/li&gt;
&lt;li&gt;shared UI state&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avoid it for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;rapidly changing values&lt;/li&gt;
&lt;li&gt;highly local state&lt;/li&gt;
&lt;li&gt;giant global stores&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And most importantly:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Context is powerful, but every update can trigger re-renders.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Use it thoughtfully, keep contexts focused, and your React architecture will stay clean and scalable.&lt;/p&gt;

&lt;p&gt;In the next episode of &lt;strong&gt;Let’s Master React Hooks Together&lt;/strong&gt;, we’ll explore one of React’s most misunderstood hooks:&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;code&gt;useRef&lt;/code&gt; — how React remembers values without causing re-renders.
&lt;/h1&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Stop Using Links the Wrong Way — Master useNavigate in React</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Wed, 06 May 2026 14:43:20 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/stop-using-links-the-wrong-way-master-usenavigate-in-react-5c52</link>
      <guid>https://dev.to/kathirvel-s/stop-using-links-the-wrong-way-master-usenavigate-in-react-5c52</guid>
      <description>&lt;p&gt;Hey… welcome back 👋&lt;/p&gt;

&lt;p&gt;If you made it here, you’re not just &lt;em&gt;learning React&lt;/em&gt; anymore —&lt;br&gt;
you’re starting to &lt;strong&gt;think like a React developer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Episode 3&lt;/strong&gt;, we set up the foundation with &lt;em&gt;Browser Router&lt;/em&gt; — basically giving our app a &lt;strong&gt;navigation system&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But now comes the real question…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“Okay… routing is set. But how do I actually control navigation with logic?”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because let’s be honest —&lt;br&gt;
real apps don’t just wait for users to click links.&lt;/p&gt;

&lt;p&gt;They:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;redirect after login&lt;/li&gt;
&lt;li&gt;protect private pages&lt;/li&gt;
&lt;li&gt;move users based on conditions&lt;/li&gt;
&lt;li&gt;respond to actions instantly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 And this… is exactly where &lt;strong&gt;&lt;code&gt;useNavigate&lt;/code&gt;&lt;/strong&gt; steps in.&lt;/p&gt;


&lt;h2&gt;
  
  
  What is useNavigate?
&lt;/h2&gt;

&lt;p&gt;Let’s slow this down and really understand it.&lt;/p&gt;

&lt;p&gt;At its core, &lt;strong&gt;&lt;code&gt;useNavigate&lt;/code&gt; is a React hook that lets you change routes (pages) using JavaScript code instead of user clicks.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It gives you control over &lt;em&gt;when&lt;/em&gt; and &lt;em&gt;where&lt;/em&gt; a user should move inside your app.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Normally in a website, navigation happens when a user clicks something.&lt;br&gt;
But with &lt;code&gt;useNavigate&lt;/code&gt;, navigation can happen because &lt;strong&gt;your logic decided it should happen&lt;/strong&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  What does that actually mean?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You don’t have to wait for a user to click a link&lt;/li&gt;
&lt;li&gt;You can trigger navigation inside functions, conditions, API responses, or events&lt;/li&gt;
&lt;li&gt;Your app becomes smarter and more responsive&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Instead of the user driving the app, sometimes the app drives the user.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  Why Does useNavigate Exist?
&lt;/h2&gt;

&lt;p&gt;To understand this properly, you need to compare traditional websites vs React apps.&lt;/p&gt;
&lt;h3&gt;
  
  
  Traditional Website Navigation
&lt;/h3&gt;

&lt;p&gt;In a normal website:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User clicks a link&lt;/li&gt;
&lt;li&gt;Browser requests a new page from the server&lt;/li&gt;
&lt;li&gt;Entire page reloads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is slow and breaks the user experience.&lt;/p&gt;


&lt;h3&gt;
  
  
  React (Single Page Application) Navigation
&lt;/h3&gt;

&lt;p&gt;React works differently.&lt;/p&gt;

&lt;p&gt;It’s a &lt;strong&gt;Single Page Application (SPA)&lt;/strong&gt;, which means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The page does not fully reload&lt;/li&gt;
&lt;li&gt;Only the required components update&lt;/li&gt;
&lt;li&gt;Navigation feels instant and smooth&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But here’s the catch:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If there are no full page reloads… how do we move between pages?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s where React Router comes in (Episode 3).&lt;br&gt;
And &lt;strong&gt;&lt;code&gt;useNavigate&lt;/code&gt; is part of that system.&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  The Real Reason useNavigate Exists
&lt;/h2&gt;

&lt;p&gt;Let’s move into real-world thinking.&lt;/p&gt;

&lt;p&gt;Modern apps are not just about showing pages. They are about &lt;strong&gt;flows&lt;/strong&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  Real-Time Scenarios
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;After login → go to dashboard&lt;/li&gt;
&lt;li&gt;After form submission → go to success page&lt;/li&gt;
&lt;li&gt;If user is not logged in → redirect to login&lt;/li&gt;
&lt;li&gt;If payment is successful → show confirmation page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are not user-click actions. These are &lt;strong&gt;logic-driven decisions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That is exactly why &lt;code&gt;useNavigate&lt;/code&gt; exists.&lt;/p&gt;


&lt;h2&gt;
  
  
  Real-Time Examples
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. After Login
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useNavigate&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-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Login&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;navigate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useNavigate&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;handleLogin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isAuthenticated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isAuthenticated&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/dashboard&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="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleLogin&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;Login&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. After Form Submission
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/thank-you&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;h3&gt;
  
  
  3. Protecting Private Routes
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/login&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;h3&gt;
  
  
  4. Auto Redirect After Delay
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Where Can You Use useNavigate?
&lt;/h2&gt;

&lt;p&gt;Important rule:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useNavigate can only be used inside:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React functional components&lt;/li&gt;
&lt;li&gt;Custom hooks&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  How to Use useNavigate (Step by Step)
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Import
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useNavigate&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-router-dom&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;
  
  
  2. Initialize
&lt;/h3&gt;


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

&lt;/div&gt;

&lt;h3&gt;
  
  
  3. Use
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/home&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;h2&gt;
  
  
  Additional Useful Patterns (Real Understanding)
&lt;/h2&gt;

&lt;p&gt;These patterns are used heavily in real applications.&lt;/p&gt;


&lt;h3&gt;
  
  
  1. Go Back to Previous Page
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&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;h4&gt;
  
  
  Meaning
&lt;/h4&gt;

&lt;p&gt;Works like browser back button.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-1&lt;/code&gt; → go back one page&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-2&lt;/code&gt; → go back two pages&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example Flow
&lt;/h4&gt;

&lt;p&gt;Home → Products → Product Details&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&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;You return to &lt;strong&gt;Products page&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Replace Current Page (No Back Navigation)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/home&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;replace&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;h4&gt;
  
  
  Meaning
&lt;/h4&gt;

&lt;p&gt;Replaces current page in history.&lt;/p&gt;

&lt;p&gt;User cannot go back to previous page.&lt;/p&gt;

&lt;h4&gt;
  
  
  Real Example: Login
&lt;/h4&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;handleLogin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/dashboard&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;replace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without replace → user goes back to login page&lt;br&gt;
With replace → login page is removed from history&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Pass Data While Navigating
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/profile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&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;h4&gt;
  
  
  Meaning
&lt;/h4&gt;

&lt;p&gt;Send temporary data to another page.&lt;/p&gt;

&lt;h4&gt;
  
  
  Receiving Data
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useLocation&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-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useLocation&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;location&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;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;h4&gt;
  
  
  Real Use Case
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/profile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&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;John&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Link vs useNavigate
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;User clicks navigation&lt;/td&gt;
&lt;td&gt;Link&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logic decides navigation&lt;/td&gt;
&lt;td&gt;useNavigate&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Common Mistakes Beginners Make (and How to Avoid Them)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Using useNavigate Outside Component
&lt;/h3&gt;

&lt;p&gt;Hooks only work inside components.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Forgetting Router Setup
&lt;/h3&gt;

&lt;p&gt;Make sure BrowserRouter is configured (Episode 3).&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Overusing useNavigate
&lt;/h3&gt;

&lt;p&gt;Don’t replace all links with it.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Navigating Before Logic Completes
&lt;/h3&gt;

&lt;p&gt;Always wait for API success or conditions.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. Ignoring Edge Cases
&lt;/h3&gt;

&lt;p&gt;Handle failures before redirecting.&lt;/p&gt;




&lt;h2&gt;
  
  
  Simple Way to Remember
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;User action → Link&lt;/li&gt;
&lt;li&gt;App logic → useNavigate&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;&lt;code&gt;useNavigate&lt;/code&gt; is not just about switching pages.&lt;/p&gt;

&lt;p&gt;It allows you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Control user flow&lt;/li&gt;
&lt;li&gt;Build real-world app behavior&lt;/li&gt;
&lt;li&gt;Create smooth, intelligent navigation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you understand this, you stop thinking in pages and start thinking in &lt;strong&gt;user journeys&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  See you in next one
&lt;/h2&gt;

&lt;p&gt;This is Episode 4 of the series &lt;strong&gt;“Let’s Master React Hooks Together.”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Full series here:&lt;br&gt;
👉 &lt;a href="https://dev.to/kathirvel-s/series/39103"&gt;https://dev.to/kathirvel-s/series/39103&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next episode, we’ll explore another powerful concept that helps your React apps become even more dynamic and interactive.&lt;/p&gt;

&lt;p&gt;Until then, try building a small project using &lt;code&gt;useNavigate&lt;/code&gt;. That’s where real understanding begins.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Stop Using Links the Wrong Way — Master useNavigate in React</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Wed, 06 May 2026 14:43:20 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/stop-using-links-the-wrong-way-master-usenavigate-in-react-2p78</link>
      <guid>https://dev.to/kathirvel-s/stop-using-links-the-wrong-way-master-usenavigate-in-react-2p78</guid>
      <description>&lt;p&gt;Hey… welcome back 👋&lt;/p&gt;

&lt;p&gt;If you made it here, you’re not just &lt;em&gt;learning React&lt;/em&gt; anymore —&lt;br&gt;
you’re starting to &lt;strong&gt;think like a React developer&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Episode 3&lt;/strong&gt;, we set up the foundation with &lt;em&gt;Browser Router&lt;/em&gt; — basically giving our app a &lt;strong&gt;navigation system&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But now comes the real question…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“Okay… routing is set. But how do I actually control navigation with logic?”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because let’s be honest —&lt;br&gt;
real apps don’t just wait for users to click links.&lt;/p&gt;

&lt;p&gt;They:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;redirect after login&lt;/li&gt;
&lt;li&gt;protect private pages&lt;/li&gt;
&lt;li&gt;move users based on conditions&lt;/li&gt;
&lt;li&gt;respond to actions instantly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 And this… is exactly where &lt;strong&gt;&lt;code&gt;useNavigate&lt;/code&gt;&lt;/strong&gt; steps in.&lt;/p&gt;


&lt;h2&gt;
  
  
  What is useNavigate?
&lt;/h2&gt;

&lt;p&gt;Let’s slow this down and really understand it.&lt;/p&gt;

&lt;p&gt;At its core, &lt;strong&gt;&lt;code&gt;useNavigate&lt;/code&gt; is a React hook that lets you change routes (pages) using JavaScript code instead of user clicks.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In simple terms:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It gives you control over &lt;em&gt;when&lt;/em&gt; and &lt;em&gt;where&lt;/em&gt; a user should move inside your app.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Normally in a website, navigation happens when a user clicks something.&lt;br&gt;
But with &lt;code&gt;useNavigate&lt;/code&gt;, navigation can happen because &lt;strong&gt;your logic decided it should happen&lt;/strong&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  What does that actually mean?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You don’t have to wait for a user to click a link&lt;/li&gt;
&lt;li&gt;You can trigger navigation inside functions, conditions, API responses, or events&lt;/li&gt;
&lt;li&gt;Your app becomes smarter and more responsive&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Instead of the user driving the app, sometimes the app drives the user.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  Why Does useNavigate Exist?
&lt;/h2&gt;

&lt;p&gt;To understand this properly, you need to compare traditional websites vs React apps.&lt;/p&gt;
&lt;h3&gt;
  
  
  Traditional Website Navigation
&lt;/h3&gt;

&lt;p&gt;In a normal website:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User clicks a link&lt;/li&gt;
&lt;li&gt;Browser requests a new page from the server&lt;/li&gt;
&lt;li&gt;Entire page reloads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is slow and breaks the user experience.&lt;/p&gt;


&lt;h3&gt;
  
  
  React (Single Page Application) Navigation
&lt;/h3&gt;

&lt;p&gt;React works differently.&lt;/p&gt;

&lt;p&gt;It’s a &lt;strong&gt;Single Page Application (SPA)&lt;/strong&gt;, which means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The page does not fully reload&lt;/li&gt;
&lt;li&gt;Only the required components update&lt;/li&gt;
&lt;li&gt;Navigation feels instant and smooth&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But here’s the catch:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If there are no full page reloads… how do we move between pages?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s where React Router comes in (Episode 3).&lt;br&gt;
And &lt;strong&gt;&lt;code&gt;useNavigate&lt;/code&gt; is part of that system.&lt;/strong&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  The Real Reason useNavigate Exists
&lt;/h2&gt;

&lt;p&gt;Let’s move into real-world thinking.&lt;/p&gt;

&lt;p&gt;Modern apps are not just about showing pages. They are about &lt;strong&gt;flows&lt;/strong&gt;.&lt;/p&gt;


&lt;h3&gt;
  
  
  Real-Time Scenarios
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;After login → go to dashboard&lt;/li&gt;
&lt;li&gt;After form submission → go to success page&lt;/li&gt;
&lt;li&gt;If user is not logged in → redirect to login&lt;/li&gt;
&lt;li&gt;If payment is successful → show confirmation page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are not user-click actions. These are &lt;strong&gt;logic-driven decisions&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That is exactly why &lt;code&gt;useNavigate&lt;/code&gt; exists.&lt;/p&gt;


&lt;h2&gt;
  
  
  Real-Time Examples
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. After Login
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useNavigate&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-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Login&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;navigate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useNavigate&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;handleLogin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isAuthenticated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isAuthenticated&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/dashboard&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="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleLogin&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;Login&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. After Form Submission
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleSubmit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/thank-you&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;h3&gt;
  
  
  3. Protecting Private Routes
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/login&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;h3&gt;
  
  
  4. Auto Redirect After Delay
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&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="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Where Can You Use useNavigate?
&lt;/h2&gt;

&lt;p&gt;Important rule:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useNavigate can only be used inside:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React functional components&lt;/li&gt;
&lt;li&gt;Custom hooks&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  How to Use useNavigate (Step by Step)
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Import
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useNavigate&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-router-dom&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;
  
  
  2. Initialize
&lt;/h3&gt;


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

&lt;/div&gt;

&lt;h3&gt;
  
  
  3. Use
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/home&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;h2&gt;
  
  
  Additional Useful Patterns (Real Understanding)
&lt;/h2&gt;

&lt;p&gt;These patterns are used heavily in real applications.&lt;/p&gt;


&lt;h3&gt;
  
  
  1. Go Back to Previous Page
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&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;h4&gt;
  
  
  Meaning
&lt;/h4&gt;

&lt;p&gt;Works like browser back button.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-1&lt;/code&gt; → go back one page&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-2&lt;/code&gt; → go back two pages&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Example Flow
&lt;/h4&gt;

&lt;p&gt;Home → Products → Product Details&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&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;You return to &lt;strong&gt;Products page&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Replace Current Page (No Back Navigation)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/home&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;replace&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;h4&gt;
  
  
  Meaning
&lt;/h4&gt;

&lt;p&gt;Replaces current page in history.&lt;/p&gt;

&lt;p&gt;User cannot go back to previous page.&lt;/p&gt;

&lt;h4&gt;
  
  
  Real Example: Login
&lt;/h4&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;handleLogin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/dashboard&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;replace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without replace → user goes back to login page&lt;br&gt;
With replace → login page is removed from history&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Pass Data While Navigating
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/profile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John&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;h4&gt;
  
  
  Meaning
&lt;/h4&gt;

&lt;p&gt;Send temporary data to another page.&lt;/p&gt;

&lt;h4&gt;
  
  
  Receiving Data
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useLocation&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-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Profile&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useLocation&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;location&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;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;h4&gt;
  
  
  Real Use Case
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;navigate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/profile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;5&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;John&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Link vs useNavigate
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Use&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;User clicks navigation&lt;/td&gt;
&lt;td&gt;Link&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Logic decides navigation&lt;/td&gt;
&lt;td&gt;useNavigate&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;




&lt;h2&gt;
  
  
  Common Mistakes Beginners Make (and How to Avoid Them)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Using useNavigate Outside Component
&lt;/h3&gt;

&lt;p&gt;Hooks only work inside components.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. Forgetting Router Setup
&lt;/h3&gt;

&lt;p&gt;Make sure BrowserRouter is configured (Episode 3).&lt;/p&gt;




&lt;h3&gt;
  
  
  3. Overusing useNavigate
&lt;/h3&gt;

&lt;p&gt;Don’t replace all links with it.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Navigating Before Logic Completes
&lt;/h3&gt;

&lt;p&gt;Always wait for API success or conditions.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. Ignoring Edge Cases
&lt;/h3&gt;

&lt;p&gt;Handle failures before redirecting.&lt;/p&gt;




&lt;h2&gt;
  
  
  Simple Way to Remember
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;User action → Link&lt;/li&gt;
&lt;li&gt;App logic → useNavigate&lt;/li&gt;
&lt;/ul&gt;




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

&lt;p&gt;&lt;code&gt;useNavigate&lt;/code&gt; is not just about switching pages.&lt;/p&gt;

&lt;p&gt;It allows you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Control user flow&lt;/li&gt;
&lt;li&gt;Build real-world app behavior&lt;/li&gt;
&lt;li&gt;Create smooth, intelligent navigation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once you understand this, you stop thinking in pages and start thinking in &lt;strong&gt;user journeys&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  See you in next one
&lt;/h2&gt;

&lt;p&gt;This is Episode 4 of the series &lt;strong&gt;“Let’s Master React Hooks Together.”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Full series here:&lt;br&gt;
👉 &lt;a href="https://dev.to/kathirvel-s/series/39103"&gt;https://dev.to/kathirvel-s/series/39103&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the next episode, we’ll explore another powerful concept that helps your React apps become even more dynamic and interactive.&lt;/p&gt;

&lt;p&gt;Until then, try building a small project using &lt;code&gt;useNavigate&lt;/code&gt;. That’s where real understanding begins.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Browser Router in React JS — Why It Exists, What It Solves, and How to Actually Use It</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Mon, 04 May 2026 02:54:56 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/browser-router-in-react-js-why-it-exists-what-it-solves-and-how-to-actually-use-it-40ig</link>
      <guid>https://dev.to/kathirvel-s/browser-router-in-react-js-why-it-exists-what-it-solves-and-how-to-actually-use-it-40ig</guid>
      <description>&lt;p&gt;If you’ve ever built a React app and thought,&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“Why does my page reload every time I click a link?”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;you’re not alone.&lt;/p&gt;

&lt;p&gt;That moment is usually where things start getting interesting… &lt;/p&gt;

&lt;p&gt;and where something like &lt;strong&gt;Browser Router&lt;/strong&gt; quietly steps in to save your user experience.&lt;/p&gt;

&lt;p&gt;And if you’re following along with my series&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Mastering React Hooks Together"&lt;/strong&gt;,&lt;/p&gt;

&lt;p&gt;this is the &lt;strong&gt;3rd episode&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;and trust me, this piece matters more than it looks. &lt;/p&gt;

&lt;p&gt;Because before jumping into hooks like &lt;code&gt;useNavigate&lt;/code&gt;, there’s something fundamental you need to understand first… and that’s exactly what we’re unpacking here.&lt;/p&gt;

&lt;p&gt;Let’s break it down in a way that actually makes sense — no robotic explanations, no unnecessary jargon. Just real understanding.&lt;/p&gt;




&lt;h2&gt;
  
  
  So… Why Does Browser Router Even Exist?
&lt;/h2&gt;

&lt;p&gt;React is built for speed and smoothness. It updates parts of the page without refreshing the whole thing. But here’s the catch:&lt;/p&gt;

&lt;p&gt;👉 Browsers don’t work that way by default.&lt;/p&gt;

&lt;p&gt;When you click a normal link (&lt;code&gt;&amp;lt;a href="/about"&amp;gt;&lt;/code&gt;), the browser reloads the entire page. That means:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your app resets&lt;/li&gt;
&lt;li&gt;State is lost&lt;/li&gt;
&lt;li&gt;It feels slow and clunky&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not exactly the “modern app” experience we want.&lt;/p&gt;

&lt;p&gt;This is where Browser Router comes in — it lets your React app behave like a real single-page application (SPA), where navigation feels instant.&lt;/p&gt;

&lt;p&gt;But how does it actually pull that off?&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Browser Router (Official + Simple)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Official idea:&lt;/strong&gt;&lt;br&gt;
Browser Router is a routing component that uses the &lt;strong&gt;browser’s History API&lt;/strong&gt; to keep your UI in sync with the URL.&lt;/p&gt;

&lt;p&gt;Now in plain English:&lt;/p&gt;

&lt;p&gt;👉 It watches the URL and decides what component to show — &lt;em&gt;without refreshing the page.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Think of it like a smart traffic controller:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;URL changes → Browser Router reacts → React renders the right component&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No reloads. No flicker. Just smooth transitions.&lt;/p&gt;

&lt;p&gt;And once you see it in action, you’ll realize it’s not just “nice to have” — it’s essential.&lt;/p&gt;


&lt;h2&gt;
  
  
  The Problem It Actually Solves
&lt;/h2&gt;

&lt;p&gt;Let’s paint a quick picture.&lt;/p&gt;

&lt;p&gt;Imagine you’re building a simple app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Home page&lt;/li&gt;
&lt;li&gt;About page&lt;/li&gt;
&lt;li&gt;Contact page&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without routing, you’d either:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Reload the page every time (bad UX), or&lt;/li&gt;
&lt;li&gt;Manually control everything with state (messy and hard to scale)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Neither feels right.&lt;/p&gt;

&lt;p&gt;Browser Router solves this by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keeping the UI and URL in sync&lt;/li&gt;
&lt;li&gt;Letting users bookmark/share links&lt;/li&gt;
&lt;li&gt;Enabling back/forward navigation&lt;/li&gt;
&lt;li&gt;Avoiding full page reloads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically, it gives your React app a &lt;strong&gt;real navigation system&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And once navigation is handled cleanly, the next natural question becomes…&lt;/p&gt;


&lt;h2&gt;
  
  
  How Do You Actually Use Browser Router?
&lt;/h2&gt;

&lt;p&gt;Let’s keep this practical — but this time, not just &lt;em&gt;what&lt;/em&gt; to write… also &lt;em&gt;why each line exists&lt;/em&gt;, so nothing feels like magic.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Install React Router
&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;react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;This installs the routing library your app doesn’t have by default.
React itself doesn’t handle routing — so you’re bringing in the tool that will.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;
  
  
  Step 2: Wrap Your App
&lt;/h3&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;BrowserRouter&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-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Your routes go here */&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;BrowserRouter&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;Let’s break this down:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;import { BrowserRouter }...&lt;/code&gt;&lt;br&gt;
👉 You’re importing the component that enables routing using the browser’s URL.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;BrowserRouter&amp;gt;&lt;/code&gt;&lt;br&gt;
👉 This is the &lt;strong&gt;engine&lt;/strong&gt; of your routing system.&lt;br&gt;
It listens to URL changes and provides routing context to everything inside it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;{/* Your routes go here */}&lt;/code&gt;&lt;br&gt;
👉 This is where your app’s pages will live — but they only work because they’re inside Browser Router.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So at this point:&lt;br&gt;
👉 Your app is now &lt;em&gt;aware&lt;/em&gt; of URLs.&lt;/p&gt;

&lt;p&gt;But it still doesn’t know what to render for each URL… and that leads us to the next step.&lt;/p&gt;


&lt;h3&gt;
  
  
  Step 3: Define Routes
&lt;/h3&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;Routes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Route&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-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&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;Routes&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;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;element&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;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="p"&gt;/&amp;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;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt; &lt;span class="na"&gt;element&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;lt;&lt;/span&gt;&lt;span class="nc"&gt;About&lt;/span&gt; &lt;span class="p"&gt;/&amp;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;Routes&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;BrowserRouter&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;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;import { Routes, Route }...&lt;/code&gt;&lt;br&gt;
👉 These help you define &lt;em&gt;which component should show for which URL&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Routes&amp;gt;&lt;/code&gt;&lt;br&gt;
👉 Think of this as a container that holds all your route rules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Route path="/" element={&amp;lt;Home /&amp;gt;} /&amp;gt;&lt;/code&gt;&lt;br&gt;
👉 When the URL is &lt;code&gt;/&lt;/code&gt;, React renders the &lt;code&gt;Home&lt;/code&gt; component.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Route path="/about" element={&amp;lt;About /&amp;gt;} /&amp;gt;&lt;/code&gt;&lt;br&gt;
👉 When the URL is &lt;code&gt;/about&lt;/code&gt;, React switches to the &lt;code&gt;About&lt;/code&gt; component.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now something important just happened:&lt;br&gt;
👉 Your app can now &lt;strong&gt;map URLs to UI&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But how does the user actually move between these URLs without reloading?&lt;/p&gt;


&lt;h3&gt;
  
  
  Step 4: Navigate Without Reloading
&lt;/h3&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;Link&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-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/about"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Go to About&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&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;Let’s unpack it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;import { Link }...&lt;/code&gt;&lt;br&gt;
👉 This replaces the normal &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag in React apps.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;&amp;lt;Link to="/about"&amp;gt;&lt;/code&gt;&lt;br&gt;
👉 Instead of reloading the page, it updates the URL &lt;em&gt;internally&lt;/em&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Go to About&lt;/code&gt;&lt;br&gt;
👉 What the user clicks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So when clicked:&lt;br&gt;
👉 URL changes → Browser Router detects it → सही component renders → no reload&lt;/p&gt;

&lt;p&gt;And now everything connects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Browser Router watches the URL&lt;/li&gt;
&lt;li&gt;Routes decide what to render&lt;/li&gt;
&lt;li&gt;Link changes the URL smoothly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s the full loop.&lt;/p&gt;

&lt;p&gt;And once this loop clicks in your head, navigation stops feeling confusing… and starts feeling powerful.&lt;/p&gt;


&lt;h2&gt;
  
  
  When Should You Use Browser Router?
&lt;/h2&gt;

&lt;p&gt;Short answer?&lt;/p&gt;

&lt;p&gt;👉 Almost always — if you're building a web app.&lt;/p&gt;

&lt;p&gt;But let’s be specific.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;You have multiple pages/views&lt;/li&gt;
&lt;li&gt;You want clean URLs&lt;/li&gt;
&lt;li&gt;You care about user experience&lt;/li&gt;
&lt;li&gt;You don’t want page reloads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Avoid it only if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your app is extremely small (like a single static view)&lt;/li&gt;
&lt;li&gt;Or you’re using a different routing strategy (like hash-based routing for legacy setups)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Otherwise, Browser Router is your go-to.&lt;/p&gt;

&lt;p&gt;And once navigation is set up, clicking links is just one part of the story…&lt;/p&gt;


&lt;h2&gt;
  
  
  Is Browser Router Just for useNavigate?
&lt;/h2&gt;

&lt;p&gt;Not exactly — but it makes it possible.&lt;/p&gt;

&lt;p&gt;Browser Router is the &lt;strong&gt;foundation&lt;/strong&gt;.&lt;br&gt;
Hooks like &lt;code&gt;useNavigate&lt;/code&gt; are tools built on top of it.&lt;/p&gt;

&lt;p&gt;Without Browser Router:&lt;br&gt;
👉 &lt;code&gt;useNavigate&lt;/code&gt; won’t work.&lt;/p&gt;

&lt;p&gt;With Browser Router:&lt;br&gt;
👉 You can programmatically move users around your app.&lt;/p&gt;

&lt;p&gt;And this is exactly why understanding Browser Router comes &lt;em&gt;before&lt;/em&gt; learning &lt;code&gt;useNavigate&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;useNavigate&lt;/code&gt; depends on routing context&lt;/li&gt;
&lt;li&gt;That context is created by Browser Router&lt;/li&gt;
&lt;li&gt;Without it, navigation logic simply has nowhere to run&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So if you jump straight into &lt;code&gt;useNavigate&lt;/code&gt; without this base, things will feel confusing or even break entirely.&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useNavigate&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-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;navigate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useNavigate&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;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;navigate&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&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;
      Go to About
    &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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where things shift from “basic routing” to “controlled user flow.”&lt;/p&gt;

&lt;p&gt;Now you’re not just linking pages — you’re guiding users.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bringing It All Together
&lt;/h2&gt;

&lt;p&gt;Browser Router isn’t just another library piece you install and forget.&lt;/p&gt;

&lt;p&gt;It’s what transforms your React app from:&lt;br&gt;
👉 A collection of components&lt;br&gt;
into&lt;br&gt;
👉 A real, navigable application&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Eliminates full page reloads&lt;/li&gt;
&lt;li&gt;Keeps URLs meaningful&lt;/li&gt;
&lt;li&gt;Improves performance and UX&lt;/li&gt;
&lt;li&gt;Enables powerful navigation patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And once you start using it, you’ll wonder how you ever built apps without it.&lt;/p&gt;




&lt;h2&gt;
  
  
  One Last Thought
&lt;/h2&gt;

&lt;p&gt;If you’re continuing this journey with &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“Mastering React Hooks Together”&lt;/strong&gt;,&lt;/p&gt;

&lt;p&gt;this 3rd episode sets the stage for everything that comes next.&lt;/p&gt;

&lt;p&gt;Because when we step into hooks like &lt;code&gt;useNavigate&lt;/code&gt;, you won’t just memorize syntax — you’ll actually understand &lt;em&gt;what’s happening under the hood&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;And that’s the difference between using React… and mastering it.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>The First Website on the Internet (And the Problem It Solved)</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Sun, 03 May 2026 06:05:23 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/the-first-website-on-the-internet-and-the-problem-it-solved-31aa</link>
      <guid>https://dev.to/kathirvel-s/the-first-website-on-the-internet-and-the-problem-it-solved-31aa</guid>
      <description>&lt;h2&gt;
  
  
  A random question… or the start of something bigger?
&lt;/h2&gt;

&lt;p&gt;Some conversations don’t feel important when they start… but they stay with you.&lt;/p&gt;

&lt;p&gt;This happened at Payilagam Institute.&lt;/p&gt;

&lt;p&gt;It was one of those normal days — nothing planned, nothing serious.&lt;/p&gt;

&lt;p&gt;Me and my friends — Mohanakumar, Hariharan, Dhanraj, and Vinayagam — were just sitting together, casually talking tech.&lt;/p&gt;

&lt;p&gt;And like always… React entered the conversation 😄&lt;/p&gt;

&lt;p&gt;Then came the question:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“Why do we even use React?”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not in a deep, interview-type way. Just casually.&lt;/p&gt;

&lt;p&gt;Hariharan stepped in and said,&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;“Back in the 1990s, websites were static… no interactivity, nothing dynamic.”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That one line changed the vibe.&lt;/p&gt;

&lt;p&gt;I started thinking…&lt;/p&gt;

&lt;p&gt;Static websites?&lt;br&gt;
No updates?&lt;br&gt;
No user interaction?&lt;/p&gt;

&lt;p&gt;Then what were websites even &lt;em&gt;for&lt;/em&gt;?&lt;/p&gt;

&lt;p&gt;And without even planning it, I asked:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;“Okay… then which was the first website ever created? And who created it?”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There was a small pause.&lt;/p&gt;

&lt;p&gt;No one had a clear answer.&lt;/p&gt;

&lt;p&gt;And that silence?&lt;/p&gt;

&lt;p&gt;That’s where this story started.&lt;/p&gt;




&lt;h2&gt;
  
  
  Welcome to the series
&lt;/h2&gt;

&lt;p&gt;This is &lt;strong&gt;Episode 1&lt;/strong&gt; of:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Sunday Source – I Break It, Then Explain It&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here, I pick one concept, break it into simple ideas, and explain it like we’re just talking.&lt;/p&gt;

&lt;p&gt;Because understanding &amp;gt; memorizing.&lt;/p&gt;

&lt;p&gt;And today… we’re going back to the origin of the web.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why I named this series “Sunday Source – I Break It, Then Explain It”
&lt;/h2&gt;

&lt;p&gt;Before we go deeper, let me tell you why this series even exists.&lt;/p&gt;

&lt;p&gt;The name is not random.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;“Sunday Source”&lt;/strong&gt; — because every Sunday, I pick one core idea (a &lt;em&gt;source&lt;/em&gt;)&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;“I Break It, Then Explain It”&lt;/strong&gt; — because complex things only make sense when you break them down&lt;/p&gt;

&lt;p&gt;No over-complication.&lt;br&gt;
No memorizing definitions.&lt;/p&gt;

&lt;p&gt;Just understanding things from the root.&lt;/p&gt;

&lt;p&gt;Because most of the time, we don’t struggle with &lt;em&gt;learning&lt;/em&gt;…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We struggle with &lt;strong&gt;how it’s explained&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This series fixes that.&lt;/p&gt;




&lt;h2&gt;
  
  
  The First Website Ever Created
&lt;/h2&gt;

&lt;p&gt;Let’s go back to 1991.&lt;/p&gt;

&lt;p&gt;The very first website in the world was created by &lt;strong&gt;Tim Berners-Lee&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;👉 You can still visit it here: &lt;a href="http://info.cern.ch/" rel="noopener noreferrer"&gt;http://info.cern.ch/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open it.&lt;/p&gt;

&lt;p&gt;It feels… almost empty.&lt;/p&gt;

&lt;p&gt;No styling. No images. Just plain text and links.&lt;/p&gt;

&lt;p&gt;But this wasn’t just a website.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This was the &lt;strong&gt;starting point of the World Wide Web&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Why was it named like that? (info.cern.ch)
&lt;/h2&gt;

&lt;p&gt;At first glance, the name &lt;strong&gt;info.cern.ch&lt;/strong&gt; might look random.&lt;/p&gt;

&lt;p&gt;But it actually tells a story.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;info&lt;/strong&gt; → because the website was meant to share &lt;em&gt;information&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;cern&lt;/strong&gt; → the organization where Tim Berners-Lee was working&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;.ch&lt;/strong&gt; → the country domain for Switzerland (where CERN is located)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the name literally means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;“Information at CERN”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;No branding. No marketing thinking.&lt;/p&gt;

&lt;p&gt;Just pure purpose.&lt;/p&gt;

&lt;p&gt;And that itself tells you something about the early web:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It was built to &lt;strong&gt;share knowledge&lt;/strong&gt;, not to impress.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Who is Tim Berners-Lee?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Tim Berners-Lee&lt;/strong&gt; is a British scientist.&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.amazonaws.com%2Fuploads%2Farticles%2Fhalyhceh7fcpiith9ppw.webp" 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.amazonaws.com%2Fuploads%2Farticles%2Fhalyhceh7fcpiith9ppw.webp" alt=" " width="612" height="391"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But more importantly…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;He is the person who made the web usable.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;He wasn’t trying to create social media, startups, or apps.&lt;/p&gt;

&lt;p&gt;He was trying to solve a very real, very practical problem.&lt;/p&gt;

&lt;p&gt;While working at CERN, he saw something frustrating:&lt;/p&gt;

&lt;p&gt;People had information… but no easy way to share it.&lt;/p&gt;




&lt;h2&gt;
  
  
  The problem he faced
&lt;/h2&gt;

&lt;p&gt;At CERN:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Different systems couldn’t communicate properly&lt;/li&gt;
&lt;li&gt;Files were stored in different formats&lt;/li&gt;
&lt;li&gt;There was no single place to access information&lt;/li&gt;
&lt;li&gt;You had to manually figure out where things were&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It was messy.&lt;/p&gt;

&lt;p&gt;Time-consuming.&lt;/p&gt;

&lt;p&gt;And inefficient.&lt;/p&gt;




&lt;h2&gt;
  
  
  The idea that changed everything
&lt;/h2&gt;

&lt;p&gt;Tim thought:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What if all this information could be connected?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Not copied. Not moved.&lt;/p&gt;

&lt;p&gt;Just… connected.&lt;/p&gt;

&lt;p&gt;So that you could jump from one document to another instantly.&lt;/p&gt;

&lt;p&gt;That’s where the idea of &lt;strong&gt;hyperlinks&lt;/strong&gt; came in.&lt;/p&gt;

&lt;p&gt;Click → move → explore.&lt;/p&gt;

&lt;p&gt;Sounds normal today.&lt;/p&gt;

&lt;p&gt;Back then?&lt;/p&gt;

&lt;p&gt;Revolutionary.&lt;/p&gt;




&lt;h2&gt;
  
  
  How he made it real
&lt;/h2&gt;

&lt;p&gt;Ideas are easy.&lt;/p&gt;

&lt;p&gt;Building them is not.&lt;/p&gt;

&lt;p&gt;But Tim Berners-Lee actually built the system from scratch.&lt;/p&gt;

&lt;p&gt;He created:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;HTML&lt;/strong&gt; → to structure content&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;HTTP&lt;/strong&gt; → to transfer data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;URL&lt;/strong&gt; → to locate resources&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The first web server&lt;/li&gt;
&lt;li&gt;The first browser&lt;/li&gt;
&lt;li&gt;The first website&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything we use today…&lt;/p&gt;

&lt;p&gt;Started from these building blocks.&lt;/p&gt;




&lt;h2&gt;
  
  
  What the first website actually did
&lt;/h2&gt;

&lt;p&gt;The first website wasn’t for fun or business.&lt;/p&gt;

&lt;p&gt;It was a guide.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;What the World Wide Web is&lt;/li&gt;
&lt;li&gt;How to create web pages&lt;/li&gt;
&lt;li&gt;How to link documents&lt;/li&gt;
&lt;li&gt;How to access information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In a way…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The first website was teaching people how to use the web itself.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Why this still matters
&lt;/h2&gt;

&lt;p&gt;Think about your daily life.&lt;/p&gt;

&lt;p&gt;Every click you make…&lt;br&gt;
Every link you open…&lt;br&gt;
Every page you visit…&lt;/p&gt;

&lt;p&gt;All of it traces back to this one idea:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Connecting information in a simple way&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;From that one page…&lt;/p&gt;

&lt;p&gt;Came everything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search engines&lt;/li&gt;
&lt;li&gt;Social media&lt;/li&gt;
&lt;li&gt;Modern frameworks like React&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So when we ask “why do we use React?”&lt;/p&gt;

&lt;p&gt;We’re actually continuing a journey that started in 1991.&lt;/p&gt;




&lt;h2&gt;
  
  
  A better way to look at it
&lt;/h2&gt;

&lt;p&gt;That small question I asked that day…&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Who created the first website?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It wasn’t just about history.&lt;/p&gt;

&lt;p&gt;It was about understanding something deeper.&lt;/p&gt;

&lt;p&gt;Every tool we use today exists because:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Someone had a problem… and decided to solve it.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once again Read it&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Someone had a problem… and decided to solve it.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Tim Berners-Lee didn’t build the web to become famous.&lt;/p&gt;

&lt;p&gt;He built it because sharing information was hard.&lt;/p&gt;

&lt;p&gt;That’s it.&lt;/p&gt;

&lt;p&gt;Simple problem. Powerful solution.&lt;/p&gt;

&lt;p&gt;So next time you learn a new technology…&lt;/p&gt;

&lt;p&gt;Don’t just ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“How does this work?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;“Why was this created in the first place?”&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because when you understand the &lt;em&gt;why&lt;/em&gt;…&lt;/p&gt;

&lt;p&gt;Everything else starts making sense.&lt;/p&gt;




&lt;p&gt;If this made you pause, think, or look at the internet a little differently…&lt;/p&gt;

&lt;p&gt;Then this series is doing its job.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Sunday Source – I Break It, Then Explain It&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Simple ideas. Clear understanding. Real connection.&lt;/p&gt;

&lt;p&gt;And next time you open a website…&lt;/p&gt;

&lt;p&gt;You’ll know where it all started.&lt;/p&gt;

&lt;p&gt;See you in the next &lt;strong&gt;Sunday Source&lt;/strong&gt;.&lt;/p&gt;

</description>
      <category>learning</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>sundaysource</category>
    </item>
    <item>
      <title>useEffect in React — the invisible engine behind real apps</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Fri, 01 May 2026 14:04:44 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/useeffect-in-react-the-invisible-engine-behind-real-apps-5fn8</link>
      <guid>https://dev.to/kathirvel-s/useeffect-in-react-the-invisible-engine-behind-real-apps-5fn8</guid>
      <description>&lt;p&gt;In Part 1 of &lt;strong&gt;“Let’s Master React Hooks Together”&lt;/strong&gt; we focused on &lt;code&gt;useState&lt;/code&gt; — how React remembers things, updates UI, and keeps everything in sync.&lt;/p&gt;

&lt;p&gt;You learned how to control your app.&lt;/p&gt;

&lt;p&gt;But then comes the next question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What happens when your app needs to talk to the outside world?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You open Instagram, blink once… and boom — your feed is alive.&lt;/p&gt;

&lt;p&gt;Posts load. Stories appear. Notifications sneak in. Everything feels instant.&lt;/p&gt;

&lt;p&gt;But here’s what most beginners don’t realize:&lt;/p&gt;

&lt;p&gt;👉 React didn’t do that.&lt;br&gt;
👉 React only rendered the empty screen.&lt;/p&gt;

&lt;p&gt;Everything after that — fetching data, syncing with APIs, setting up listeners…&lt;/p&gt;

&lt;p&gt;That’s where &lt;code&gt;useEffect&lt;/code&gt; steps in.&lt;/p&gt;

&lt;p&gt;This is where React stops being just about state…&lt;br&gt;
and starts becoming interactive with the real world.&lt;/p&gt;

&lt;p&gt;And once you truly understand this hook:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You stop just managing state… and start thinking like React.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h2&gt;
  
  
  So what is &lt;code&gt;useEffect&lt;/code&gt;… really?
&lt;/h2&gt;

&lt;p&gt;Let’s skip the robotic definition for a second.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;code&gt;useEffect&lt;/code&gt; lets your component do things &lt;em&gt;after&lt;/em&gt; it renders.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now the official version (just so you’re covered):&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“The Effect Hook lets you perform side effects in function components.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Cool. But what does that actually mean?&lt;/p&gt;


&lt;h2&gt;
  
  
  “Side Effects” — sounds scary, isn’t.
&lt;/h2&gt;

&lt;p&gt;Relax. It’s simpler than it sounds.&lt;/p&gt;

&lt;p&gt;A side effect is anything your component does that is &lt;strong&gt;not just returning UI&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think about real apps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fetching data from a server &lt;/li&gt;
&lt;li&gt;Updating the page title &lt;/li&gt;
&lt;li&gt;Listening to scroll or clicks &lt;/li&gt;
&lt;li&gt;Running a timer &lt;/li&gt;
&lt;li&gt;Saving something in local storage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 These don’t directly render JSX — but they &lt;em&gt;make your app feel alive.&lt;/em&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Why does &lt;code&gt;useEffect&lt;/code&gt; even exist?
&lt;/h2&gt;

&lt;p&gt;Because React is strict about one thing:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Rendering must stay pure.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;ul&gt;
&lt;li&gt;Same input → same UI output&lt;/li&gt;
&lt;li&gt;No hidden behavior&lt;/li&gt;
&lt;li&gt;No randomness during render&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But real apps? Total chaos &lt;/p&gt;

&lt;p&gt;Let’s bring back the Instagram example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open app → fetch posts&lt;/li&gt;
&lt;li&gt;Like a post → send data to server&lt;/li&gt;
&lt;li&gt;Scroll → load more content&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;👉 None of this is “rendering UI.”&lt;/p&gt;

&lt;p&gt;So React needed a safe place for this “messy” stuff.&lt;/p&gt;

&lt;p&gt;And it basically said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Do whatever you want… just don’t do it during render.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That safe place = &lt;code&gt;useEffect&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  The exact problem it solves (this is the aha moment)
&lt;/h2&gt;

&lt;p&gt;Imagine writing 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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Feed&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fetchPosts&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// ❌ dangerous&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks innocent. But here’s what really happens:&lt;/p&gt;

&lt;p&gt;→ Component renders&lt;br&gt;
→ &lt;code&gt;fetchPosts()&lt;/code&gt; runs&lt;br&gt;
→ Data changes → triggers render&lt;br&gt;
→ It runs again&lt;br&gt;
→ And again…&lt;/p&gt;

&lt;p&gt;You’ve just created a loop.&lt;/p&gt;



&lt;p&gt;Now watch the same thing done properly:&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;Feed&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;posts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPosts&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="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;fetchPosts&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setPosts&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="nx"&gt;posts&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First render → UI shows empty state&lt;br&gt;
Then &lt;code&gt;useEffect&lt;/code&gt; runs → fetch starts&lt;br&gt;
Data arrives → state updates&lt;br&gt;
Component re-renders → UI updates&lt;/p&gt;

&lt;p&gt;👉 No chaos. No loops. Just control.&lt;/p&gt;


&lt;h2&gt;
  
  
  The mental model that changes everything
&lt;/h2&gt;

&lt;p&gt;Forget technical jargon. Think like this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“What should happen &lt;em&gt;after&lt;/em&gt; the screen updates?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That answer = your &lt;code&gt;useEffect&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  How to actually use &lt;code&gt;useEffect&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Here’s the shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// effect logic&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="c1"&gt;// cleanup logic&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;dependencies&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let’s &lt;em&gt;feel&lt;/em&gt; what each part does.&lt;/p&gt;




&lt;h3&gt;
  
  
  Effect running every time
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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;Rendering happened&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;Render → effect runs&lt;br&gt;
Render again → runs again&lt;/p&gt;

&lt;p&gt;👉 No control. Just chaos checking everything.&lt;/p&gt;


&lt;h3&gt;
  
  
  Run only once (most common beginner case)
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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;Component loaded&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;Component appears → effect runs once&lt;br&gt;
Never again&lt;/p&gt;

&lt;p&gt;👉 Perfect for API calls, initial setup.&lt;/p&gt;


&lt;h3&gt;
  
  
  Run when something changes
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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;User 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;user&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Initial render → runs&lt;br&gt;
If &lt;code&gt;user&lt;/code&gt; changes → runs again&lt;br&gt;
If nothing changes → does nothing&lt;/p&gt;

&lt;p&gt;👉 This is where real apps live.&lt;/p&gt;


&lt;h2&gt;
  
  
  Cleanup — the part most people ignore (big mistake)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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;const&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;Checking notifications...&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;3000&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;Component loads → interval starts&lt;br&gt;
Every 3 seconds → it runs&lt;/p&gt;

&lt;p&gt;Now imagine leaving the page…&lt;/p&gt;

&lt;p&gt;Without cleanup:&lt;br&gt;
The interval keeps running&lt;br&gt;
Multiple intervals stack &lt;br&gt;
App slows down &lt;/p&gt;

&lt;p&gt;With cleanup:&lt;br&gt;
React removes the interval cleanly&lt;br&gt;
Nothing leaks&lt;br&gt;
Everything stays predictable&lt;/p&gt;

&lt;p&gt;👉 Cleanup runs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Before the effect runs again&lt;/li&gt;
&lt;li&gt;When the component disappears&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Lifecycle… but explained like a human
&lt;/h2&gt;

&lt;p&gt;Forget the textbook words.&lt;/p&gt;

&lt;p&gt;Here’s what actually happens:&lt;/p&gt;

&lt;p&gt;🟢 Component shows up&lt;br&gt;
→ UI renders&lt;br&gt;
→ &lt;code&gt;useEffect&lt;/code&gt; runs&lt;/p&gt;

&lt;p&gt;🟡 Something changes&lt;br&gt;
→ React updates UI&lt;br&gt;
→ &lt;code&gt;useEffect&lt;/code&gt; checks dependencies&lt;br&gt;
→ Runs only if needed&lt;/p&gt;

&lt;p&gt;🔴 Component goes away&lt;br&gt;
→ Cleanup runs&lt;/p&gt;

&lt;p&gt;That’s the whole story.&lt;/p&gt;


&lt;h2&gt;
  
  
  Where you should use &lt;code&gt;useEffect&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Use it when your app needs to:&lt;/p&gt;

&lt;p&gt;✔ Fetch data (feeds, dashboards, profiles)&lt;br&gt;
✔ Listen to events (scroll, resize, clicks)&lt;br&gt;
✔ Sync with APIs or storage&lt;br&gt;
✔ Run timers or intervals&lt;br&gt;
✔ Handle subscriptions (live chats, notifications)&lt;/p&gt;


&lt;h2&gt;
  
  
  When NOT to use it (this saves hours of frustration)
&lt;/h2&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;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;setFullName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;first&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;last&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;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;last&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates unnecessary re-renders.&lt;/p&gt;

&lt;p&gt;Better:&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;fullName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;first&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;last&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing async&lt;br&gt;
No external system&lt;br&gt;
No side effect&lt;/p&gt;

&lt;p&gt;👉 Then you don’t need &lt;code&gt;useEffect&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Real-world example (Instagram-style thinking)
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Stories&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;userId&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;stories&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setStories&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="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;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/stories/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;userId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;active&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;setStories&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;active&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="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;userId&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;stories&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;story&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;img&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;story&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;src&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;story&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;))}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Component appears → empty stories render&lt;br&gt;
Effect runs → fetch starts for current user&lt;br&gt;
When data returns → it checks if component is still active&lt;br&gt;
If yes → updates state → UI refreshes&lt;/p&gt;

&lt;p&gt;Now if user switches quickly:&lt;br&gt;
Cleanup runs → marks previous request inactive&lt;br&gt;
Old data won’t overwrite new UI&lt;/p&gt;

&lt;p&gt;👉 This is how real apps avoid subtle bugs.&lt;/p&gt;




&lt;h2&gt;
  
  
  The shift that makes you dangerous (in a good way)
&lt;/h2&gt;

&lt;p&gt;Most beginners ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“How do I use &lt;code&gt;useEffect&lt;/code&gt;?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But better developers ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Should this even be an effect?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That one question will level you up faster than anything else.&lt;/p&gt;




&lt;h2&gt;
  
  
  Next time you open an app…
&lt;/h2&gt;

&lt;p&gt;Whether it’s Instagram, YouTube, or anything dynamic…&lt;/p&gt;

&lt;p&gt;Ask yourself:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What ran after the UI loaded?&lt;/li&gt;
&lt;li&gt;What triggered that update?&lt;/li&gt;
&lt;li&gt;What got cleaned up when I left?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That curiosity turns confusion into clarity.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final takeaway
&lt;/h2&gt;

&lt;p&gt;So in this second part of &lt;strong&gt;“Let’s Master React Hooks Together”&lt;/strong&gt; you moved beyond &lt;code&gt;useState&lt;/code&gt;…&lt;/p&gt;

&lt;p&gt;…and stepped into &lt;code&gt;useEffect&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Not just a hook — but a mindset shift.&lt;/p&gt;

&lt;p&gt;Because &lt;code&gt;useEffect&lt;/code&gt; is the bridge between:&lt;/p&gt;

&lt;p&gt;React’s clean, predictable state world&lt;br&gt;
The messy, asynchronous real world&lt;/p&gt;

&lt;p&gt;When you understand that bridge:&lt;/p&gt;

&lt;p&gt;You stop writing “just code.”&lt;br&gt;
You start designing behavior.&lt;/p&gt;

&lt;p&gt;You know when things should run.&lt;br&gt;
You know why they run.&lt;/p&gt;

&lt;p&gt;And that’s when React starts to feel less like magic…&lt;br&gt;
and more like a tool you actually control.&lt;/p&gt;

&lt;p&gt;In the next part, we’ll keep building on this — making your hooks cleaner, smarter, and more predictable.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Hooks Made Simple: Mastering useState (Without Losing Your Mind)</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Tue, 28 Apr 2026 15:26:15 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/react-hooks-made-simple-mastering-usestate-without-losing-your-mind-4m16</link>
      <guid>https://dev.to/kathirvel-s/react-hooks-made-simple-mastering-usestate-without-losing-your-mind-4m16</guid>
      <description>&lt;p&gt;Let’s be honest—when you first hear “React Hooks”, it sounds a bit intimidating. Like something only senior developers casually throw around while sipping coffee&lt;/p&gt;

&lt;p&gt;But here’s the truth: &lt;strong&gt;Hooks are not scary&lt;/strong&gt;.&lt;br&gt;
In fact, once you understand just one of them—&lt;code&gt;useState&lt;/code&gt;—you unlock a huge part of React.&lt;/p&gt;

&lt;p&gt;Think of this as building something step by step. Each piece adds meaning, and suddenly everything makes sense.&lt;/p&gt;

&lt;p&gt;And that’s exactly why this is part of a series called &lt;strong&gt;“Let’s Master React Hooks Together”&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Because learning React (or honestly, anything in tech) becomes much easier when you don’t try to swallow everything at once. A series gives you structure. It keeps you consistent. It removes confusion about what to learn next. And most importantly, it builds discipline—one small concept at a time, instead of random jumping between topics.&lt;/p&gt;

&lt;p&gt;When you follow a guided path like this, you’re not just learning React Hooks… you’re training your mind to learn efficiently, stay consistent, and actually finish what you start.&lt;/p&gt;

&lt;p&gt;So instead of rushing, we go step by step—starting with &lt;code&gt;useState&lt;/code&gt; and building real confidence along the way.&lt;/p&gt;


&lt;h2&gt;
  
  
  So… Why Do We Even Need &lt;code&gt;useState&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; exists to help your component &lt;strong&gt;remember things over time&lt;/strong&gt; and update the UI when those things change.&lt;/p&gt;

&lt;p&gt;Imagine you’re writing a number on a whiteboard:&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;let&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;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;function Counter()&lt;/code&gt; → this creates a component that React will run every time it renders&lt;br&gt;
&lt;code&gt;let count = 0;&lt;/code&gt; → a normal variable is created and always starts fresh at 0&lt;br&gt;
&lt;code&gt;return &amp;lt;h1&amp;gt;{count}&amp;lt;/h1&amp;gt;;&lt;/code&gt; → React displays the current value on screen&lt;/p&gt;

&lt;p&gt;You write &lt;strong&gt;0&lt;/strong&gt;. Someone says “increase it”… but every time the component runs again, it goes back to &lt;strong&gt;0&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That’s exactly what happens here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every render resets the value&lt;/li&gt;
&lt;li&gt;Nothing is remembered&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So your app behaves like it has &lt;em&gt;no memory at all&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;➡️ We need a way to &lt;strong&gt;remember what happened before&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  What Exactly is &lt;code&gt;useState&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useState&lt;/code&gt; gives your component a memory slot that survives re-renders.&lt;/p&gt;

&lt;p&gt;Let’s upgrade that whiteboard to something smarter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="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="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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;import { useState } from "react";&lt;/code&gt; → brings the state feature into your component&lt;br&gt;
&lt;code&gt;function Counter()&lt;/code&gt; → React runs this function to render UI&lt;br&gt;
&lt;code&gt;const [count, setCount] = useState(0);&lt;/code&gt; →&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;count&lt;/code&gt; holds the current value&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;setCount&lt;/code&gt; is used to update it&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;0&lt;/code&gt; is the starting value&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;return &amp;lt;h1&amp;gt;{count}&amp;lt;/h1&amp;gt;;&lt;/code&gt; → displays the stored value&lt;/p&gt;

&lt;p&gt;Now imagine a digital display:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it remembers the number&lt;/li&gt;
&lt;li&gt;it doesn’t reset unless you tell it to&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we can store it… how do we change it?&lt;/p&gt;


&lt;h2&gt;
  
  
  How to Use &lt;code&gt;useState&lt;/code&gt; (The Simple Way)
&lt;/h2&gt;

&lt;p&gt;We need a way to update the value.&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="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="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nx"&gt;Increment&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt; → creates a clickable element&lt;br&gt;
&lt;code&gt;onClick={() =&amp;gt; ...}&lt;/code&gt; → tells React what to do when clicked&lt;br&gt;
&lt;code&gt;() =&amp;gt; setCount(count + 1)&lt;/code&gt; →&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;takes current value&lt;/li&gt;
&lt;li&gt;adds 1&lt;/li&gt;
&lt;li&gt;sends it to React&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;setCount(...)&lt;/code&gt; → updates the stored value&lt;br&gt;
React sees the update → re-renders the component → new value appears&lt;/p&gt;

&lt;p&gt;It’s like pressing a counter device:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;click&lt;/li&gt;
&lt;li&gt;number increases&lt;/li&gt;
&lt;li&gt;display updates instantly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s bring everything together into one working piece.&lt;/p&gt;


&lt;h2&gt;
  
  
  Let’s Build Something: Counter App
&lt;/h2&gt;

&lt;p&gt;Here’s the full setup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="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="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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="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="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Increment&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;Counter&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;import { useState } from "react";&lt;/code&gt; → enables state in this component&lt;br&gt;
&lt;code&gt;function Counter()&lt;/code&gt; → defines the UI logic&lt;br&gt;
&lt;code&gt;useState(0)&lt;/code&gt; → sets starting value&lt;br&gt;
&lt;code&gt;count&lt;/code&gt; → holds current number&lt;br&gt;
&lt;code&gt;setCount&lt;/code&gt; → updates that number&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;h1&amp;gt;{count}&amp;lt;/h1&amp;gt;&lt;/code&gt; → shows the current value&lt;/p&gt;

&lt;p&gt;&lt;code&gt;onClick={() =&amp;gt; setCount(count + 1)}&lt;/code&gt; →&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;user clicks&lt;/li&gt;
&lt;li&gt;value increases&lt;/li&gt;
&lt;li&gt;React updates UI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;export default Counter;&lt;/code&gt; → allows this component to be used elsewhere&lt;/p&gt;

&lt;p&gt;Picture a scoreboard:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;starts at 0&lt;/li&gt;
&lt;li&gt;every click adds a point&lt;/li&gt;
&lt;li&gt;display updates instantly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that you’ve seen it working, let’s understand when to use this.&lt;/p&gt;


&lt;h2&gt;
  
  
  When Should You Use &lt;code&gt;useState&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;useState&lt;/code&gt; when something &lt;strong&gt;changes over time and needs to be shown on screen&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Imagine filling out a form:&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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;useState("")&lt;/code&gt; → starts with empty text&lt;br&gt;
&lt;code&gt;name&lt;/code&gt; → stores what user types&lt;br&gt;
&lt;code&gt;setName&lt;/code&gt; → updates it&lt;/p&gt;

&lt;p&gt;When connected to input:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;user types&lt;/li&gt;
&lt;li&gt;value updates&lt;/li&gt;
&lt;li&gt;UI reflects instantly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s like typing on your phone—each letter appears immediately.&lt;/p&gt;

&lt;p&gt;But not everything needs this kind of memory.&lt;/p&gt;


&lt;h2&gt;
  
  
  When NOT to Use &lt;code&gt;useState&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Sometimes, keeping track is unnecessary.&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;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Welcome&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;&lt;code&gt;const title&lt;/code&gt; → simple fixed value&lt;br&gt;
No updates → no re-render needed&lt;/p&gt;

&lt;p&gt;Like a printed poster:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;always the same&lt;/li&gt;
&lt;li&gt;no interaction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let’s see where it becomes really powerful.&lt;/p&gt;


&lt;h2&gt;
  
  
  Real-Life Situations Where &lt;code&gt;useState&lt;/code&gt; Shines
&lt;/h2&gt;

&lt;p&gt;Here’s where things get exciting.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Form Input
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;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="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;value={name}&lt;/code&gt; → input shows current state&lt;br&gt;
&lt;code&gt;onChange&lt;/code&gt; → listens for typing&lt;br&gt;
&lt;code&gt;e.target.value&lt;/code&gt; → gets typed text&lt;br&gt;
&lt;code&gt;setName(...)&lt;/code&gt; → updates state&lt;br&gt;
React re-renders → input stays in sync&lt;/p&gt;


&lt;h3&gt;
  
  
  2. Toggle Feature
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isOpen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsOpen&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setIsOpen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;isOpen&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;Toggle&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;isOpen&lt;/code&gt; → current state (true/false)&lt;br&gt;
&lt;code&gt;setIsOpen&lt;/code&gt; → updates it&lt;br&gt;
&lt;code&gt;!isOpen&lt;/code&gt; → flips value&lt;/p&gt;

&lt;p&gt;Click → value changes → UI updates&lt;/p&gt;


&lt;h3&gt;
  
  
  3. Conditional Rendering
&lt;/h3&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;isOpen&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Visible&lt;/span&gt; &lt;span class="nx"&gt;now&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;code&gt;isOpen &amp;amp;&amp;amp;&lt;/code&gt; → checks condition&lt;br&gt;
If true → show content&lt;br&gt;
If false → hide content&lt;/p&gt;

&lt;p&gt;State controls visibility.&lt;/p&gt;

&lt;p&gt;Now let’s sharpen how we update things.&lt;/p&gt;


&lt;h2&gt;
  
  
  Pro Tips (That Make You Look Smart)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&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="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;&lt;code&gt;prev&lt;/code&gt; → latest value from React&lt;br&gt;
&lt;code&gt;prev + 1&lt;/code&gt; → safe update&lt;br&gt;
Prevents outdated values&lt;/p&gt;

&lt;p&gt;Useful when multiple updates happen quickly.&lt;/p&gt;


&lt;h2&gt;
  
  
  Common Beginner Mistakes
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&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="c1"&gt;// ❌ wrong&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This changes the variable… but:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React doesn’t track it&lt;/li&gt;
&lt;li&gt;No re-render happens&lt;/li&gt;
&lt;li&gt;UI stays the same&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Correct approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React sees update → re-renders → UI updates&lt;/p&gt;




&lt;h2&gt;
  
  
  So What Did We Learn?
&lt;/h2&gt;

&lt;p&gt;You started with something that resets every time…&lt;br&gt;
and turned it into something that remembers, updates, and reacts.&lt;/p&gt;

&lt;p&gt;Now your UI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;keeps track of changes&lt;/li&gt;
&lt;li&gt;updates instantly&lt;/li&gt;
&lt;li&gt;feels alive&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s the magic of &lt;code&gt;useState&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What’s Next? (And Why You Should Care)
&lt;/h2&gt;

&lt;p&gt;Now you know how to store and update values.&lt;/p&gt;

&lt;p&gt;But what if:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;something needs to happen automatically after rendering?&lt;/li&gt;
&lt;li&gt;you fetch data from an API?&lt;/li&gt;
&lt;li&gt;you deal with timers or external events?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s where the next step comes in…&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;&lt;code&gt;useEffect&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you combine both, you move from simple interactions to real-world applications.&lt;/p&gt;




&lt;h2&gt;
  
  
  Before You Go…
&lt;/h2&gt;

&lt;p&gt;Try this:&lt;/p&gt;

&lt;p&gt;👉 Add a &lt;strong&gt;decrement button&lt;/strong&gt;&lt;br&gt;
👉 Stop it from going below 0&lt;br&gt;
👉 Add a reset button&lt;/p&gt;

&lt;p&gt;Watch how every action:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;updates the value&lt;/li&gt;
&lt;li&gt;refreshes the UI&lt;/li&gt;
&lt;li&gt;keeps everything in sync&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s when it really clicks.&lt;/p&gt;




&lt;p&gt;Once you start seeing it this way, React stops feeling confusing…&lt;br&gt;
and starts feeling like something you can actually control&lt;/p&gt;




</description>
      <category>react</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>How React + Vite Actually Works Behind the Scenes Breakdown</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Sun, 26 Apr 2026 07:03:58 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/how-react-vite-actually-works-behind-the-scenes-breakdown-37no</link>
      <guid>https://dev.to/kathirvel-s/how-react-vite-actually-works-behind-the-scenes-breakdown-37no</guid>
      <description>&lt;p&gt;You type &lt;code&gt;npm run dev&lt;/code&gt;, press Enter… and your React app shows up instantly in the browser.&lt;/p&gt;

&lt;p&gt;It feels effortless.&lt;/p&gt;

&lt;p&gt;But here’s the thing — &lt;em&gt;it shouldn’t feel like magic if you really want to get good at this.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As A2D Nandha puts it:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“If you want to crack it, you need to understand the system.”&lt;/p&gt;
&lt;/blockquote&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.amazonaws.com%2Fuploads%2Farticles%2F36k371iz2vps51bgba3d.jpg" 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.amazonaws.com%2Fuploads%2Farticles%2F36k371iz2vps51bgba3d.jpg" alt=" " width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That idea hits hard, especially in development. Because behind that one simple command, a full system wakes up — a dev server spins up, modules start flowing, transformations happen in milliseconds, and your browser begins assembling your app piece by piece.&lt;/p&gt;

&lt;p&gt;So naturally, the question comes up:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What actually just happened after I hit that command?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you’ve ever been curious about that moment — not just using the tool, but truly understanding it — you’re in the right place.&lt;/p&gt;

&lt;p&gt;Let’s walk through it like you’re watching the whole system come alive in real time.&lt;/p&gt;




&lt;h2&gt;
  
  
  Dev Server Initialization (&lt;code&gt;npm run dev&lt;/code&gt; &amp;amp; Vite CLI)
&lt;/h2&gt;

&lt;p&gt;The moment you run this command, your system reads the &lt;code&gt;package.json&lt;/code&gt; file and executes the script mapped to &lt;code&gt;"dev"&lt;/code&gt; — usually something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This starts a &lt;strong&gt;development server&lt;/strong&gt; on your machine.&lt;/p&gt;

&lt;p&gt;A development server is simply a local program that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Serves your files to the browser&lt;/li&gt;
&lt;li&gt;Watches for changes&lt;/li&gt;
&lt;li&gt;Updates your app instantly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of it less like “running your app” and more like “making your app available to the browser on demand.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick picture in your head:&lt;/strong&gt;&lt;br&gt;
It’s like opening a live streaming room. You haven’t started the content yet — but the room is ready, the camera is on, and viewers (your browser) can now connect.&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.amazonaws.com%2Fuploads%2Farticles%2Fa63geh21v7rnmpeif3uj.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.amazonaws.com%2Fuploads%2Farticles%2Fa63geh21v7rnmpeif3uj.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, nothing is bundled. Nothing is optimized. Vite is just getting ready to serve files &lt;em&gt;as they are&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;And that’s where things start getting interesting.&lt;/p&gt;


&lt;h2&gt;
  
  
  On-Demand Module Serving (Vite Dev Server vs Bundlers)
&lt;/h2&gt;

&lt;p&gt;Traditional tools like Webpack bundle your entire app before showing anything in the browser.&lt;/p&gt;

&lt;p&gt;Vite flips that idea completely.&lt;/p&gt;

&lt;p&gt;Instead of preparing everything upfront, Vite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Starts the server instantly&lt;/li&gt;
&lt;li&gt;Waits for the browser to request files&lt;/li&gt;
&lt;li&gt;Sends only what’s needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is possible because modern browsers understand something powerful: &lt;strong&gt;ES Modules&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Imagine this:&lt;/strong&gt;&lt;br&gt;
You walk into a library. Instead of getting a giant stack of &lt;em&gt;every&lt;/em&gt; book you might need, you just ask for one book at a time — exactly when you need it.&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.amazonaws.com%2Fuploads%2Farticles%2F05bvk1aaiki9azauamb3.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.amazonaws.com%2Fuploads%2Farticles%2F05bvk1aaiki9azauamb3.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Less waiting. Less overload. More speed.&lt;/p&gt;


&lt;h2&gt;
  
  
  Native ES Modules (ESM) in the Browser
&lt;/h2&gt;

&lt;p&gt;In older setups, browsers couldn’t handle &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;export&lt;/code&gt; directly. Everything had to be bundled into one big file.&lt;/p&gt;

&lt;p&gt;Now, with ES Modules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each file is treated as a module&lt;/li&gt;
&lt;li&gt;The browser can request them individually&lt;/li&gt;
&lt;li&gt;Dependencies are resolved step-by-step&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So when your browser loads your app, it doesn’t download one giant file.&lt;/p&gt;

&lt;p&gt;Instead, it reads your entry file and follows the import chain like a map.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Think about it like Google Maps:&lt;/strong&gt;&lt;br&gt;
You don’t load the entire world map in full detail. You zoom into your route, and more details load as needed.&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.amazonaws.com%2Fuploads%2Farticles%2F6rrgvgwhbhv8u98xpcdu.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.amazonaws.com%2Fuploads%2Farticles%2F6rrgvgwhbhv8u98xpcdu.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s exactly how your app is being loaded.&lt;/p&gt;


&lt;h2&gt;
  
  
  Application Entry Point (&lt;code&gt;main.jsx&lt;/code&gt; Bootstrapping)
&lt;/h2&gt;

&lt;p&gt;Your app begins execution from a file 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="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;jsx&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file usually does 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="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&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;import&lt;/span&gt; &lt;span class="nx"&gt;ReactDOM&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-dom/client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&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;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the root of your application.&lt;/p&gt;

&lt;p&gt;From here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The browser loads &lt;code&gt;App.jsx&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Then any components inside it&lt;/li&gt;
&lt;li&gt;Then their dependencies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s a chain reaction — one import leads to another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Picture this:&lt;/strong&gt;&lt;br&gt;
It’s like turning the first domino. Once it falls, everything else follows in sequence — clean, predictable, and controlled.&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.amazonaws.com%2Fuploads%2Farticles%2Fae23jytgzqceixklqciu.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.amazonaws.com%2Fuploads%2Farticles%2Fae23jytgzqceixklqciu.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  JSX Transpilation (ESBuild &amp;amp; React Transform)
&lt;/h2&gt;

&lt;p&gt;Here’s something important:&lt;/p&gt;

&lt;p&gt;Browsers do &lt;strong&gt;not&lt;/strong&gt; understand JSX.&lt;/p&gt;

&lt;p&gt;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;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello&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;…is not valid JavaScript.&lt;/p&gt;

&lt;p&gt;So before the browser can execute your code, JSX must be converted into plain JavaScript.&lt;/p&gt;

&lt;p&gt;Vite uses &lt;strong&gt;ESBuild&lt;/strong&gt; to do this transformation on the fly.&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello&lt;span class="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;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="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&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 transformation happens:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instantly&lt;/li&gt;
&lt;li&gt;In memory&lt;/li&gt;
&lt;li&gt;Without slowing down your app&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Think of it like subtitles in a movie:&lt;/strong&gt;&lt;br&gt;
You’re watching content in one language (JSX), but your brain (browser) understands another (JavaScript). Vite quietly translates it in real time — no delay, no interruption.&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.amazonaws.com%2Fuploads%2Farticles%2Fa2a8k5tj53l2gpaiyesw.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.amazonaws.com%2Fuploads%2Farticles%2Fa2a8k5tj53l2gpaiyesw.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Hot Module Replacement (HMR) Runtime
&lt;/h2&gt;

&lt;p&gt;You change one line of code… hit save… and your app updates immediately.&lt;/p&gt;

&lt;p&gt;No refresh needed.&lt;/p&gt;

&lt;p&gt;This is &lt;strong&gt;Hot Module Replacement (HMR)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here’s what’s actually happening:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Vite detects a file change&lt;/li&gt;
&lt;li&gt;It identifies which module changed&lt;/li&gt;
&lt;li&gt;It sends an update to the browser&lt;/li&gt;
&lt;li&gt;The browser replaces only that part&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So instead of reloading the entire page, only the affected component updates.&lt;/p&gt;

&lt;p&gt;This is why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your app state is preserved&lt;/li&gt;
&lt;li&gt;Updates feel instant&lt;/li&gt;
&lt;li&gt;Development feels smooth&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Imagine editing a Google Doc with live sync:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You change one sentence — and it updates instantly for everyone, without reloading the whole document.&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.amazonaws.com%2Fuploads%2Farticles%2Fihk6zbdumay680c14bw2.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.amazonaws.com%2Fuploads%2Farticles%2Fihk6zbdumay680c14bw2.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s HMR in action.&lt;/p&gt;


&lt;h2&gt;
  
  
  File System Watching (Chokidar / FS Events)
&lt;/h2&gt;

&lt;p&gt;Vite uses a &lt;strong&gt;file watcher&lt;/strong&gt; running in the background.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Monitors your project files&lt;/li&gt;
&lt;li&gt;Detects changes immediately&lt;/li&gt;
&lt;li&gt;Triggers updates when needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s constantly active while your dev server is running.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Think of it like auto-save on steroids:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The moment you hit save, something is already reacting — no button clicks, no manual refresh.&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.amazonaws.com%2Fuploads%2Farticles%2Ftbder5u2e8oht5k9oww4.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.amazonaws.com%2Fuploads%2Farticles%2Ftbder5u2e8oht5k9oww4.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  Browser Module Graph &amp;amp; Request Lifecycle
&lt;/h2&gt;

&lt;p&gt;When you open &lt;code&gt;http://localhost:5173&lt;/code&gt;, the browser:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Requests the HTML file&lt;/li&gt;
&lt;li&gt;Reads the &lt;code&gt;&amp;lt;script type="module"&amp;gt;&lt;/code&gt; tag&lt;/li&gt;
&lt;li&gt;Loads your entry file (&lt;code&gt;main.jsx&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Follows every import&lt;/li&gt;
&lt;li&gt;Requests each module from Vite&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Each request goes back to the Vite server, which:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transforms code if needed&lt;/li&gt;
&lt;li&gt;Sends it back immediately&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So your app is built &lt;em&gt;on demand&lt;/em&gt;, piece by piece.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Visualize this:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It’s like assembling a Lego model — but instead of getting the full set at once, each piece arrives exactly when you need to place it.&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.amazonaws.com%2Fuploads%2Farticles%2Fl14l34c92j0q6jio58xy.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.amazonaws.com%2Fuploads%2Farticles%2Fl14l34c92j0q6jio58xy.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  React Virtual DOM &amp;amp; Reconciliation Process
&lt;/h2&gt;

&lt;p&gt;Now here’s where React itself steps in.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Virtual DOM?
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Virtual DOM&lt;/strong&gt; is a lightweight JavaScript representation of the real DOM (the actual UI in the browser).&lt;/p&gt;

&lt;p&gt;Instead of directly updating the browser UI every time something changes, React:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creates a virtual copy of the UI&lt;/li&gt;
&lt;li&gt;Compares it with the previous version (diffing)&lt;/li&gt;
&lt;li&gt;Updates only the parts that changed&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Why does this matter?
&lt;/h3&gt;

&lt;p&gt;Direct DOM updates are slow.&lt;/p&gt;

&lt;p&gt;React avoids unnecessary work by being &lt;em&gt;smart&lt;/em&gt; about what actually needs to change.&lt;/p&gt;
&lt;h3&gt;
  
  
  Let’s make this click:
&lt;/h3&gt;

&lt;p&gt;Imagine you’re editing a large Excel sheet.&lt;/p&gt;

&lt;p&gt;You change just one cell.&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.amazonaws.com%2Fuploads%2Farticles%2Fkracnlpaez4sbbb9uwoi.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.amazonaws.com%2Fuploads%2Farticles%2Fkracnlpaez4sbbb9uwoi.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Would you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Recreate the entire sheet from scratch ❌&lt;/li&gt;
&lt;li&gt;Or update just that one cell ✅&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React chooses the second option.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Another way to see it:&lt;/strong&gt;&lt;br&gt;
Think of a food delivery app UI.&lt;/p&gt;

&lt;p&gt;If you add one item to your cart, the whole page doesn’t reload. Only the cart section updates.&lt;/p&gt;

&lt;p&gt;That’s Virtual DOM working behind the scenes — calculating the smallest possible change and applying it efficiently.&lt;/p&gt;


&lt;h2&gt;
  
  
  Production Build Pipeline (Rollup Bundling &amp;amp; Optimization)
&lt;/h2&gt;

&lt;p&gt;When you run:&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 build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Now Vite:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bundles your code using Rollup&lt;/li&gt;
&lt;li&gt;Removes unused code (tree shaking)&lt;/li&gt;
&lt;li&gt;Minifies files&lt;/li&gt;
&lt;li&gt;Optimizes assets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of many small module requests, your app becomes a few optimized files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Think of development vs production like this:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Development → flexible, fast, easy to change&lt;/li&gt;
&lt;li&gt;Production → compact, efficient, optimized&lt;/li&gt;
&lt;/ul&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.amazonaws.com%2Fuploads%2Farticles%2Fvnriqgmfxbokl5k85v9o.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.amazonaws.com%2Fuploads%2Farticles%2Fvnriqgmfxbokl5k85v9o.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s like working with raw ingredients vs serving a finished dish.&lt;/p&gt;




&lt;h2&gt;
  
  
  End-to-End Execution Flow (React + Vite Architecture Summary)
&lt;/h2&gt;

&lt;p&gt;Here’s the full flow in simple terms:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You start the dev server&lt;/li&gt;
&lt;li&gt;The browser requests your app&lt;/li&gt;
&lt;li&gt;Vite serves files as ES Modules&lt;/li&gt;
&lt;li&gt;JSX gets transformed instantly&lt;/li&gt;
&lt;li&gt;Dependencies load one by one&lt;/li&gt;
&lt;li&gt;React uses Virtual DOM to update efficiently&lt;/li&gt;
&lt;li&gt;Changes update via HMR&lt;/li&gt;
&lt;/ul&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.amazonaws.com%2Fuploads%2Farticles%2Fz0o9eo0t6vj2hy0rvxjw.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.amazonaws.com%2Fuploads%2Farticles%2Fz0o9eo0t6vj2hy0rvxjw.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No heavy startup time. No unnecessary work.&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.amazonaws.com%2Fuploads%2Farticles%2Fed9s578rsx7tbcyaiquh.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.amazonaws.com%2Fuploads%2Farticles%2Fed9s578rsx7tbcyaiquh.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just fast, on-demand execution.&lt;/p&gt;




&lt;h2&gt;
  
  
  One Thing to Try Right Now (Trace the Module Graph)
&lt;/h2&gt;

&lt;p&gt;Open your project and follow this flow manually:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start at &lt;code&gt;main.jsx&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Jump to &lt;code&gt;App.jsx&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Then open a component inside it&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now imagine the browser doing the same thing — file by file.&lt;/p&gt;

&lt;p&gt;That’s exactly how your app runs.&lt;/p&gt;




&lt;p&gt;Once you see this clearly, React + Vite stops feeling like a tool…&lt;/p&gt;

&lt;p&gt;…and starts feeling like a system you actually understand.&lt;/p&gt;




&lt;p&gt;If you want, we can go deeper next — like &lt;strong&gt;what exactly you’ll see in the Network tab and how Vite handles caching and requests internally.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Concepts That Finally Click (Vite, JSX, Components &amp; Folder Structure, npm vs npx and Dev Server)</title>
      <dc:creator>Kathirvel S</dc:creator>
      <pubDate>Sun, 19 Apr 2026 08:38:59 +0000</pubDate>
      <link>https://dev.to/kathirvel-s/react-concepts-that-finally-click-vite-jsx-components-folder-structure-and-npm-vs-npx-19pg</link>
      <guid>https://dev.to/kathirvel-s/react-concepts-that-finally-click-vite-jsx-components-folder-structure-and-npm-vs-npx-19pg</guid>
      <description>&lt;p&gt;You know that moment…&lt;/p&gt;

&lt;p&gt;You open a React project, stare at the files, run a command, and everything works —&lt;br&gt;
but deep inside you're thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I don’t fully get what just happened.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Not because you’re not capable.&lt;br&gt;
But because most explanations skip the &lt;em&gt;why&lt;/em&gt; and rush into the &lt;em&gt;how&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;So here’s a different approach.&lt;/p&gt;

&lt;p&gt;Instead of throwing definitions at you, we’re going to &lt;strong&gt;decode what’s actually happening behind the scenes&lt;/strong&gt; — the kind of understanding that sticks even when you close the tab.&lt;/p&gt;

&lt;p&gt;As you read, don’t just move your eyes.&lt;/p&gt;

&lt;p&gt;Pause. Question things. Try to connect ideas.&lt;/p&gt;

&lt;p&gt;Because if you do that, somewhere in this blog…&lt;br&gt;
something will click — and once it clicks, it doesn’t go away.&lt;/p&gt;


&lt;h1&gt;
  
  
  1. React + Vite Folder Structure (also known as “What am I even looking at?”)
&lt;/h1&gt;

&lt;p&gt;You open your project and suddenly it feels like someone dumped a suitcase full of files in front of you.&lt;/p&gt;

&lt;p&gt;But here’s the thing — nothing in there is random.&lt;/p&gt;

&lt;p&gt;A React + Vite folder structure is simply a &lt;strong&gt;well-organized system where every file has a purpose&lt;/strong&gt;, making your app easier to build, debug, and scale as it grows.&lt;/p&gt;

&lt;p&gt;Think about moving into a new house. You don’t just throw your clothes, utensils, and books into one room and hope life works out. You create spaces — kitchen for cooking, bedroom for sleeping, storage for things you don’t use daily.&lt;/p&gt;

&lt;p&gt;Your project works the same way.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;src/&lt;/code&gt; is your &lt;strong&gt;living room&lt;/strong&gt; — this is where your actual app lives&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;components/&lt;/code&gt; is your &lt;strong&gt;furniture set&lt;/strong&gt; — reusable pieces you place anywhere&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;assets/&lt;/code&gt; is your &lt;strong&gt;storage shelf&lt;/strong&gt; — images, fonts, icons&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;public/&lt;/code&gt; is like the &lt;strong&gt;front porch&lt;/strong&gt; — things that don’t change much&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;node_modules/&lt;/code&gt; is that &lt;strong&gt;locked warehouse&lt;/strong&gt; — full of dependencies you don’t touch&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And then there are two files that quietly control everything:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;main.jsx&lt;/code&gt; → the entry gate where your app starts&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;App.jsx&lt;/code&gt; → the root of your UI tree&lt;/li&gt;
&lt;/ul&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.amazonaws.com%2Fuploads%2Farticles%2Fh9ywalrv8jn9uvbfeizp.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.amazonaws.com%2Fuploads%2Farticles%2Fh9ywalrv8jn9uvbfeizp.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you see it like this, the chaos turns into a map.&lt;/p&gt;



&lt;p&gt;But wait… you didn’t manually create all this, right?&lt;/p&gt;

&lt;p&gt;Something built this structure for you in seconds.&lt;/p&gt;

&lt;p&gt;So who’s doing that heavy lifting?&lt;/p&gt;


&lt;h1&gt;
  
  
  2. npm vs npx (The Most Confusing Duo Ever)
&lt;/h1&gt;

&lt;p&gt;This is where most beginners get tripped up — not because it’s complex, but because no one explains it clearly.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm&lt;/code&gt; is your package manager. It installs tools, stores them, and lets you reuse them anytime.&lt;br&gt;
&lt;code&gt;npx&lt;/code&gt;, on the other hand, is more like a temporary executor — it runs something instantly without permanently installing it.&lt;/p&gt;

&lt;p&gt;Imagine this:&lt;/p&gt;

&lt;p&gt;You’re hungry.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One option is going grocery shopping, storing everything, and cooking daily — that’s &lt;code&gt;npm&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The other is ordering food when you need it, eating it, and moving on — that’s &lt;code&gt;npx&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When you run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-vite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re basically saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey, I need this tool right now… use it and don’t clutter my system.”&lt;/p&gt;
&lt;/blockquote&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.amazonaws.com%2Fuploads%2Farticles%2Fg0rw8ef6qzjkj0e8dvss.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.amazonaws.com%2Fuploads%2Farticles%2Fg0rw8ef6qzjkj0e8dvss.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s clean. Fast. No commitment.&lt;/p&gt;




&lt;p&gt;Now your project is created, dependencies installed, everything looks ready…&lt;/p&gt;

&lt;p&gt;And then you open a file and see something illegal-looking:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return &amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wait… JavaScript doesn’t look like this.&lt;/p&gt;

&lt;p&gt;Or does it?&lt;/p&gt;




&lt;h1&gt;
  
  
  3. What is JSX? (HTML inside JavaScript?!)
&lt;/h1&gt;

&lt;p&gt;JSX is where React stops feeling like programming… and starts feeling like building.&lt;/p&gt;

&lt;p&gt;It lets you write UI in a syntax that &lt;em&gt;looks like HTML&lt;/em&gt;, but it’s actually JavaScript under the hood. React reads this and transforms it into real browser instructions.&lt;/p&gt;

&lt;p&gt;Instead of writing long, boring DOM manipulation code like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;create element → set text → append child → repeat&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You just describe what you want:&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;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello World&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;That’s it.&lt;/p&gt;

&lt;p&gt;It’s like explaining something to a friend instead of writing a technical manual.&lt;/p&gt;

&lt;p&gt;Imagine describing your dream room.&lt;/p&gt;

&lt;p&gt;You wouldn’t say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Create four walls, apply paint, attach lighting…”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You’d say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I want a cozy room with warm lights and a desk.”&lt;/p&gt;
&lt;/blockquote&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.amazonaws.com%2Fuploads%2Farticles%2F3qa09mo2htnkcnuwirl1.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.amazonaws.com%2Fuploads%2Farticles%2F3qa09mo2htnkcnuwirl1.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JSX is that natural language for UI.&lt;/p&gt;




&lt;h3&gt;
  
  
  So… how does Vite understand &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; inside JavaScript?
&lt;/h3&gt;

&lt;p&gt;Here’s where things get really interesting.&lt;/p&gt;

&lt;p&gt;Because the truth is — &lt;strong&gt;JavaScript itself has no idea what &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; means&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So how is this even working?&lt;/p&gt;

&lt;p&gt;When you run a Vite + React app, Vite doesn’t directly “understand” JSX. Instead, it uses a fast compiler (usually &lt;strong&gt;esbuild&lt;/strong&gt; during development) along with React’s JSX transform to &lt;strong&gt;convert JSX into plain JavaScript before the browser ever sees it&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let’s break that illusion.&lt;/p&gt;

&lt;p&gt;When you write 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;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello World&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;Vite transforms it behind the scenes into 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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;jsx&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;_jsx&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/jsx-runtime&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;_jsx&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;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 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;Now suddenly… it &lt;em&gt;is&lt;/em&gt; valid JavaScript.&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.amazonaws.com%2Fuploads%2Farticles%2Fsm9stg02b25f7d25m4zv.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.amazonaws.com%2Fuploads%2Farticles%2Fsm9stg02b25f7d25m4zv.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; wasn’t HTML — it became a &lt;strong&gt;function call&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  🧠 What’s really happening step-by-step?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;You write JSX in your &lt;code&gt;.jsx&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;Vite intercepts that file during development&lt;/li&gt;
&lt;li&gt;esbuild compiles JSX → JavaScript instantly&lt;/li&gt;
&lt;li&gt;React’s runtime (&lt;code&gt;react/jsx-runtime&lt;/code&gt;) takes over&lt;/li&gt;
&lt;li&gt;It creates a virtual representation of your UI (Virtual DOM)&lt;/li&gt;
&lt;li&gt;React later turns that into real DOM in the browser&lt;/li&gt;
&lt;/ol&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.amazonaws.com%2Fuploads%2Farticles%2F2gmlr9frnd04aui26lnw.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.amazonaws.com%2Fuploads%2Farticles%2F2gmlr9frnd04aui26lnw.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All of this happens so fast that it feels like magic.&lt;/p&gt;




&lt;h3&gt;
  
  
  🎬 A quick mental picture
&lt;/h3&gt;

&lt;p&gt;Imagine you’re speaking in your native language (JSX), but the browser only understands English (JavaScript).&lt;/p&gt;

&lt;p&gt;Vite acts like a &lt;strong&gt;real-time translator&lt;/strong&gt; sitting between you and the browser.&lt;/p&gt;

&lt;p&gt;You say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;h1&amp;gt;Hello&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vite hears it, translates instantly, and tells the browser:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Create an h1 element with this text”&lt;/p&gt;
&lt;/blockquote&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.amazonaws.com%2Fuploads%2Farticles%2Fluuazncfin6u7tabkgex.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.amazonaws.com%2Fuploads%2Farticles%2Fluuazncfin6u7tabkgex.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And the browser says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Got it.”&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  ⚡ Why this feels insanely fast in Vite
&lt;/h3&gt;

&lt;p&gt;Older tools (like CRA with Webpack) used to bundle everything before running.&lt;/p&gt;

&lt;p&gt;Vite doesn’t wait.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It compiles files &lt;strong&gt;on demand&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Uses &lt;strong&gt;native ES modules&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Only processes what you actually open&lt;/li&gt;
&lt;/ul&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.amazonaws.com%2Fuploads%2Farticles%2Fizbuwvzl91mfxox7ksf2.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.amazonaws.com%2Fuploads%2Farticles%2Fizbuwvzl91mfxox7ksf2.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s why your app starts instantly and updates feel instant.&lt;/p&gt;




&lt;p&gt;Now here’s the real power move…&lt;/p&gt;

&lt;p&gt;You don’t just write JSX once.&lt;/p&gt;

&lt;p&gt;You reuse it.&lt;/p&gt;

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




&lt;h1&gt;
  
  
  🧱 4. Components in React (The LEGO System)
&lt;/h1&gt;

&lt;p&gt;React isn’t about writing big chunks of UI.&lt;/p&gt;

&lt;p&gt;It’s about breaking everything into &lt;strong&gt;small, reusable pieces&lt;/strong&gt; called components.&lt;/p&gt;

&lt;p&gt;A component is just a function that returns UI.&lt;/p&gt;

&lt;p&gt;That’s it. Nothing magical.&lt;/p&gt;

&lt;p&gt;But what makes it powerful is how you use it.&lt;/p&gt;

&lt;p&gt;Think about LEGO blocks.&lt;/p&gt;

&lt;p&gt;You don’t rebuild a door every time you need one. You create it once, then reuse it across houses, buildings, even entire cities.&lt;/p&gt;

&lt;p&gt;Same 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="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;Now imagine using it everywhere:&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;Button&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;Button&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;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;One definition. Infinite usage.&lt;/p&gt;

&lt;p&gt;This is why React apps stay clean instead of becoming spaghetti code.&lt;/p&gt;




&lt;p&gt;But here’s something that feels unnecessarily strict at first…&lt;/p&gt;

&lt;p&gt;Why does React complain if you try to return multiple elements?&lt;/p&gt;

&lt;p&gt;Why is it so obsessed with “only one root”?&lt;/p&gt;




&lt;h1&gt;
  
  
  5. Why React Components Return Only One Element
&lt;/h1&gt;

&lt;p&gt;At first, this rule feels annoying.&lt;/p&gt;

&lt;p&gt;You try 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="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;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;World&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;And React says: “Nope.”&lt;/p&gt;

&lt;p&gt;The reason is actually simple — React needs a &lt;strong&gt;single root node&lt;/strong&gt; to efficiently track and update what changes in your UI.&lt;/p&gt;

&lt;p&gt;Think of it like sending a package.&lt;/p&gt;

&lt;p&gt;If you ship five loose items separately, tracking becomes messy. But if you pack everything into one box, it’s easier to manage, deliver, and update.&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.amazonaws.com%2Fuploads%2Farticles%2Fs424i04kqph6dpsil0on.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.amazonaws.com%2Fuploads%2Farticles%2Fs424i04kqph6dpsil0on.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That “box” in React is your parent element.&lt;/p&gt;

&lt;p&gt;When you don’t want extra divs messing up your design, React gives you a clean solution:&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;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;World&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;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No extra HTML. Just structure.&lt;/p&gt;




&lt;p&gt;Now that you’re noticing syntax details…&lt;/p&gt;

&lt;p&gt;You might have seen tags 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;&amp;lt;img /&amp;gt;
&amp;lt;input /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why don’t they have closing tags?&lt;/p&gt;

&lt;p&gt;Lazy coding?&lt;/p&gt;

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




&lt;h1&gt;
  
  
  6. Why Self-Closing Tags Exist
&lt;/h1&gt;

&lt;p&gt;Some elements don’t need children.&lt;/p&gt;

&lt;p&gt;They just exist, do their job, and leave.&lt;/p&gt;

&lt;p&gt;That’s exactly what self-closing tags are — elements that don’t wrap anything inside them.&lt;/p&gt;

&lt;p&gt;Think of a vending machine.&lt;/p&gt;

&lt;p&gt;You press a button → it gives you a drink.&lt;/p&gt;

&lt;p&gt;There’s no conversation, no wrapping, no nesting.&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.amazonaws.com%2Fuploads%2Farticles%2F4tpzx0l1gilfh465skui.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.amazonaws.com%2Fuploads%2Farticles%2F4tpzx0l1gilfh465skui.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Same idea 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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"image.png"&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;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text"&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;They’re complete on their own.&lt;/p&gt;

&lt;p&gt;Cleaner code, less noise.&lt;/p&gt;




&lt;p&gt;Alright… now comes the part where everything finally comes alive.&lt;/p&gt;

&lt;p&gt;You type one command:&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
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And boom — your app appears in the browser.&lt;/p&gt;

&lt;p&gt;But what actually just happened?&lt;/p&gt;




&lt;h1&gt;
  
  
  7. What Happens When You Run &lt;code&gt;npm run dev&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;This isn’t just “run the project.”&lt;/p&gt;

&lt;p&gt;This command starts a &lt;strong&gt;development server&lt;/strong&gt;, and that server is constantly watching your code.&lt;/p&gt;

&lt;p&gt;The moment you make a change, it updates the browser instantly.&lt;/p&gt;

&lt;p&gt;No refresh. No waiting.&lt;/p&gt;

&lt;p&gt;It’s like having a chef cook right in front of you.&lt;/p&gt;

&lt;p&gt;You say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Add more spice”&lt;/p&gt;
&lt;/blockquote&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.amazonaws.com%2Fuploads%2Farticles%2F1db8p9ssj6zm80cjncgu.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.amazonaws.com%2Fuploads%2Farticles%2F1db8p9ssj6zm80cjncgu.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And immediately, the dish changes.&lt;/p&gt;

&lt;p&gt;Behind the scenes, Vite is doing some serious magic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It spins up a lightning-fast server&lt;/li&gt;
&lt;li&gt;Uses modern JavaScript modules instead of heavy bundling&lt;/li&gt;
&lt;li&gt;Injects updates into the browser instantly&lt;/li&gt;
&lt;li&gt;Keeps everything insanely fast&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why Vite feels so smooth compared to older setups.&lt;/p&gt;




&lt;p&gt;But there’s one small detail you probably noticed without thinking much…&lt;/p&gt;

&lt;p&gt;Why does Vite always run on &lt;strong&gt;5173&lt;/strong&gt;&lt;br&gt;
while Create React App sticks to &lt;strong&gt;3000&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;That’s not random.&lt;/p&gt;


&lt;h1&gt;
  
  
  🔌 7.1 Why Vite Uses Port 5173 and CRA Uses 3000
&lt;/h1&gt;

&lt;p&gt;Every time you run a dev server, your app needs a &lt;strong&gt;port&lt;/strong&gt; — basically a channel through which your browser talks to your local machine.&lt;/p&gt;

&lt;p&gt;A port is just a numbered endpoint.&lt;br&gt;
Your computer has thousands of them.&lt;/p&gt;

&lt;p&gt;So when you open:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:5173
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re not just opening a website —&lt;br&gt;
you’re connecting to a &lt;strong&gt;specific doorway inside your system&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  💻 Think of your laptop like this…
&lt;/h3&gt;

&lt;p&gt;Your laptop is like a device hub with different ports.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;USB port → for devices&lt;/li&gt;
&lt;li&gt;HDMI port → for display&lt;/li&gt;
&lt;li&gt;Charging port → for power&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each port has a purpose.&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.amazonaws.com%2Fuploads%2Farticles%2Fy9a93z53ftc5z0bhnr3d.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.amazonaws.com%2Fuploads%2Farticles%2Fy9a93z53ftc5z0bhnr3d.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now imagine if everything tried to use the same port.&lt;/p&gt;

&lt;p&gt;Nothing would work properly.&lt;/p&gt;




&lt;h3&gt;
  
  
  Same idea in software
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;CRA uses &lt;strong&gt;3000&lt;/strong&gt; as its default port&lt;/li&gt;
&lt;li&gt;Vite uses &lt;strong&gt;5173&lt;/strong&gt; as its default port&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because ports are like &lt;strong&gt;reserved seats in a system&lt;/strong&gt;.&lt;br&gt;
Each service picks a seat that’s usually free and less likely to conflict.&lt;/p&gt;

&lt;p&gt;Port 3000 became popular early, so many tools used it.&lt;br&gt;
Vite chose 5173 to avoid clashes and start fresh.&lt;/p&gt;




&lt;h3&gt;
  
  
  🎬 Simple mental image
&lt;/h3&gt;

&lt;p&gt;Think of your laptop like a hotel.&lt;/p&gt;

&lt;p&gt;Each app gets a room number (port):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React app (CRA) → Room 3000&lt;/li&gt;
&lt;li&gt;Vite app → Room 5173&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If room 5173 is busy, Vite just moves to another room automatically.&lt;/p&gt;

&lt;p&gt;No panic. No crash. Just relocation.&lt;/p&gt;




&lt;p&gt;Now that you see this…&lt;/p&gt;

&lt;p&gt;Even something as small as a number becomes part of a system that actually makes sense.&lt;/p&gt;




&lt;h1&gt;
  
  
  8. Create React App vs Vite
&lt;/h1&gt;

&lt;p&gt;At their core, both &lt;strong&gt;Create React App (CRA)&lt;/strong&gt; and &lt;strong&gt;Vite&lt;/strong&gt; are tools that help you &lt;strong&gt;set up and run a React application&lt;/strong&gt; without manually configuring everything from scratch.&lt;/p&gt;

&lt;p&gt;They both aim to solve the same problem:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“How do I start a React project quickly without dealing with complex setup?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But the way they solve it is completely different.&lt;/p&gt;




&lt;p&gt;Let’s go back to that earlier vibe…&lt;/p&gt;

&lt;p&gt;CRA is like a traditional classroom teacher — structured, step-by-step, but a bit slow when you want to move fast.&lt;/p&gt;

&lt;p&gt;Vite feels like learning from a creator who gets straight to the point — no waiting, no unnecessary setup, just instant results.&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.amazonaws.com%2Fuploads%2Farticles%2Ffanj8s0pd3tabzvxm0z1.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.amazonaws.com%2Fuploads%2Farticles%2Ffanj8s0pd3tabzvxm0z1.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Same story… but clearer now
&lt;/h3&gt;

&lt;p&gt;Imagine two ways of cooking:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CRA way:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First, prepare all ingredients&lt;/li&gt;
&lt;li&gt;Then cook everything together&lt;/li&gt;
&lt;li&gt;Only after everything is ready → you can taste&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Vite way:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start cooking immediately&lt;/li&gt;
&lt;li&gt;Prepare things as needed&lt;/li&gt;
&lt;li&gt;Taste and adjust in real-time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CRA bundles everything &lt;em&gt;before&lt;/em&gt; you see anything.&lt;br&gt;
Vite lets you see things &lt;em&gt;as they happen&lt;/em&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  Another way to see it (Aeroplane Mode ON)
&lt;/h3&gt;

&lt;p&gt;Think of building and running your app like preparing a flight.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CRA is like a flight that waits for all passengers, luggage, and checks to complete before takeoff.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Long waiting time ⏳&lt;/li&gt;
&lt;li&gt;Everything is processed upfront&lt;/li&gt;
&lt;li&gt;Once it starts, it’s stable… but slow to begin&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Vite is like a private jet.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You hop in&lt;/li&gt;
&lt;li&gt;Engine starts instantly&lt;/li&gt;
&lt;li&gt;Adjustments happen while moving&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;No long queues. No heavy delay.&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.amazonaws.com%2Fuploads%2Farticles%2Fwk11mbyfy68r1jnckzlt.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.amazonaws.com%2Fuploads%2Farticles%2Fwk11mbyfy68r1jnckzlt.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just speed.&lt;/p&gt;




&lt;h3&gt;
  
  
  What’s actually happening under the hood
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;CRA uses &lt;strong&gt;Webpack&lt;/strong&gt;, which bundles the entire app before serving&lt;/li&gt;
&lt;li&gt;Vite uses &lt;strong&gt;native ES modules&lt;/strong&gt; and serves files on demand&lt;/li&gt;
&lt;li&gt;CRA reloads the whole app&lt;/li&gt;
&lt;li&gt;Vite updates only what changed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s why Vite feels insanely fast — because it avoids unnecessary work.&lt;/p&gt;




&lt;h3&gt;
  
  
  Quick Comparison
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Create React App&lt;/th&gt;
&lt;th&gt;Vite&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Startup Time&lt;/td&gt;
&lt;td&gt;Slow&lt;/td&gt;
&lt;td&gt;⚡ Instant&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Build System&lt;/td&gt;
&lt;td&gt;Webpack&lt;/td&gt;
&lt;td&gt;Native ES Modules&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Performance&lt;/td&gt;
&lt;td&gt;Heavy&lt;/td&gt;
&lt;td&gt;Lightweight&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Developer Experience&lt;/td&gt;
&lt;td&gt;Okay&lt;/td&gt;
&lt;td&gt;Smooth &amp;amp; fast&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;CRA bundles everything before running.&lt;/p&gt;

&lt;p&gt;Vite skips that delay and serves files instantly.&lt;/p&gt;

&lt;p&gt;That’s the game changer.&lt;/p&gt;




&lt;h1&gt;
  
  
  Before You Close This Tab… Pause.
&lt;/h1&gt;

&lt;p&gt;Don’t just scroll past this part.&lt;/p&gt;

&lt;p&gt;Ask yourself honestly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Could you explain JSX to someone &lt;em&gt;without googling&lt;/em&gt;?&lt;/li&gt;
&lt;li&gt;Do you now know what actually happens when you run &lt;code&gt;npm run dev&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;When you see a React folder… does it still feel like chaos?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If even one of those shifted in your head — something changed.&lt;/p&gt;

&lt;p&gt;Not surface-level “I saw this before” knowledge…&lt;br&gt;
but &lt;strong&gt;internal clarity&lt;/strong&gt;.&lt;/p&gt;




&lt;h1&gt;
  
  
  What You Actually Walk Away With
&lt;/h1&gt;

&lt;p&gt;You didn’t just “learn React basics.”&lt;/p&gt;

&lt;p&gt;You trained your brain to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;See folders as &lt;strong&gt;systems&lt;/strong&gt;, not files&lt;/li&gt;
&lt;li&gt;See JSX as &lt;strong&gt;transformed logic&lt;/strong&gt;, not magic syntax&lt;/li&gt;
&lt;li&gt;See components as &lt;strong&gt;reusable thinking patterns&lt;/strong&gt;, not just functions&lt;/li&gt;
&lt;li&gt;See errors as &lt;strong&gt;signals&lt;/strong&gt;, not problems&lt;/li&gt;
&lt;li&gt;See tools like Vite as &lt;strong&gt;accelerators&lt;/strong&gt;, not black boxes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And most importantly…&lt;/p&gt;

&lt;p&gt;👉 You moved from &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“what is this?”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;to &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“oh… I know what’s happening here.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That shift?&lt;/p&gt;

&lt;p&gt;That’s the moment people stop being beginners.&lt;/p&gt;




&lt;h1&gt;
  
  
  Bonus: Why React &amp;amp; Vite Logos Look Like That
&lt;/h1&gt;

&lt;p&gt;Now here’s something most people never think about — the logos you see every day actually &lt;em&gt;represent the philosophy of the tools&lt;/em&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚛️ React Logo (the atom)
&lt;/h3&gt;

&lt;p&gt;The React logo looks like an &lt;strong&gt;atom with orbiting electrons&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That’s not random.&lt;/p&gt;

&lt;p&gt;It represents the idea of &lt;strong&gt;building UIs from small, independent pieces (components)&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The center = core UI logic&lt;/li&gt;
&lt;li&gt;The orbiting circles = reusable components&lt;/li&gt;
&lt;li&gt;The movement = data flow between them&lt;/li&gt;
&lt;/ul&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.amazonaws.com%2Fuploads%2Farticles%2Fslyzfn8t0xefook7nxot.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.amazonaws.com%2Fuploads%2Farticles%2Fslyzfn8t0xefook7nxot.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In short:&lt;br&gt;
👉 React = everything is made of small reusable “particles” that build big applications.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚡ Vite Logo (lightning bolt)
&lt;/h3&gt;

&lt;p&gt;The Vite logo is a &lt;strong&gt;lightning bolt wrapped in a geometric shape&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;That symbolizes one thing: &lt;strong&gt;speed&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lightning = instant response&lt;/li&gt;
&lt;li&gt;Sharp angles = modern minimal tooling&lt;/li&gt;
&lt;li&gt;Energy feel = fast dev experience&lt;/li&gt;
&lt;/ul&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.amazonaws.com%2Fuploads%2Farticles%2Fpfxel4nbups3vd3gbze3.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.amazonaws.com%2Fuploads%2Farticles%2Fpfxel4nbups3vd3gbze3.png" alt=" " width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In short:&lt;br&gt;
👉 Vite = “your app, but instantly powered and ready”&lt;/p&gt;




&lt;h3&gt;
  
  
  Final thought on logos
&lt;/h3&gt;

&lt;p&gt;If React is the &lt;em&gt;structure of thinking&lt;/em&gt;,&lt;br&gt;
Vite is the &lt;em&gt;speed of execution&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;One tells you how to build.&lt;br&gt;
The other makes it fast.&lt;/p&gt;




&lt;p&gt;Next time you open a React project…&lt;/p&gt;

&lt;p&gt;Don’t rush to code.&lt;/p&gt;

&lt;p&gt;Look at it.&lt;/p&gt;

&lt;p&gt;Understand it.&lt;/p&gt;

&lt;p&gt;Break it.&lt;/p&gt;

&lt;p&gt;Fix it.&lt;/p&gt;

&lt;p&gt;Because that’s where real developers are made &lt;/p&gt;

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