<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[We Act and Re-act]]></title><description><![CDATA[We Act and Re-act]]></description><link>https://vidushisingla.xyz</link><generator>RSS for Node</generator><lastBuildDate>Wed, 08 Apr 2026 10:47:35 GMT</lastBuildDate><atom:link href="https://vidushisingla.xyz/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Growing State Management: A Gentle Introduction to Zustand]]></title><description><![CDATA[The Garden That Grew Too Wild
Imagine you own a small garden.Every day you walk through it — watering, trimming, planting new seeds.
At first, it’s peaceful.But as your garden grows, you start keeping lists — which plant needs sunlight, which one nee...]]></description><link>https://vidushisingla.xyz/growing-state-management-a-gentle-introduction-to-zustand</link><guid isPermaLink="true">https://vidushisingla.xyz/growing-state-management-a-gentle-introduction-to-zustand</guid><category><![CDATA[React]]></category><category><![CDATA[zustand]]></category><category><![CDATA[State Management ]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Redux]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Mon, 06 Oct 2025 06:25:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759731840883/746ed664-e6dc-4688-a600-dab6126c0d60.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-the-garden-that-grew-too-wild">The Garden That Grew Too Wild</h2>
<p>Imagine you own a small garden.<br />Every day you walk through it — watering, trimming, planting new seeds.</p>
<p>At first, it’s peaceful.<br />But as your garden grows, you start keeping lists — which plant needs sunlight, which one needs trimming, and which one you just planted last week.</p>
<p>Before you know it, your peaceful garden becomes a <strong>spreadsheet of chaos</strong>.<br />You’re no longer tending to your plants — you’re <strong>managing your management</strong>.</p>
<p>If you’ve ever used <strong>Redux</strong> for state management in React, this might sound familiar.</p>
<hr />
<h2 id="heading-enter-zustand-the-self-tending-garden">Enter Zustand: The Self-Tending Garden</h2>
<p>“Zustand” means <em>“state”</em> in German.<br />It’s a <strong>lightweight, minimal, and intuitive state management library for React</strong> — one that feels like your garden finally learned to take care of itself.</p>
<p>Instead of endless reducers, dispatchers, and action types, you simply <strong>create a small store</strong> that holds your state and the logic to change it.</p>
<p>Zustand listens quietly in the background — when something changes, it updates only what’s needed, leaving the rest of your app calm and still.</p>
<hr />
<h2 id="heading-planting-your-first-seeds-creating-the-store">Planting Your First Seeds (Creating the Store)</h2>
<p>In this garden, your <strong>store is the soil</strong> — it holds the roots of every plant.</p>
<p>Here’s your first seed:</p>
<pre><code class="lang-plaintext">import { create } from 'zustand'

const useGardenStore = create((set) =&gt; ({
  plants: [],

  addPlant: (name) =&gt;
    set((state) =&gt; ({
      plants: [...state.plants, { id: Date.now(), name }]
    })),

  removePlant: (id) =&gt;
    set((state) =&gt; ({
      plants: state.plants.filter((p) =&gt; p.id !== id)
    })),
}));
</code></pre>
<p>Each <code>plant</code> is an object in your garden.<br />You can add or remove plants — and Zustand will handle the rest, without the ceremony of reducers or dispatchers.</p>
<hr />
<h2 id="heading-watching-your-plants-grow-using-the-store-in-react">Watching Your Plants Grow (Using the Store in React)</h2>
<p>Now let’s step into the garden and see how it grows:</p>
<pre><code class="lang-plaintext">import React, { useState } from 'react';
import useGardenStore from './useGardenStore';

export default function Garden() {
  const { plants, addPlant, removePlant } = useGardenStore();
  const [name, setName] = useState('');

  return (
    &lt;div&gt;
      &lt;input
        value={name}
        onChange={(e) =&gt; setName(e.target.value)}
        placeholder="Add a plant..."
      /&gt;
      &lt;button onClick={() =&gt; addPlant(name)}&gt;Plant&lt;/button&gt;

      &lt;ul&gt;
        {plants.map((p) =&gt; (
          &lt;li key={p.id}&gt;
            {p.name}
            &lt;button onClick={() =&gt; removePlant(p.id)}&gt;Remove&lt;/button&gt;
          &lt;/li&gt;
        ))}
      &lt;/ul&gt;
    &lt;/div&gt;
  );
}
</code></pre>
<p>Every click, every keystroke — your garden updates instantly.<br />Zustand automatically re-renders only what changes, keeping your React app fast and lightweight.</p>
<hr />
<h2 id="heading-making-the-garden-remember-persistent-state">Making the Garden Remember (Persistent State)</h2>
<p>What if your garden could remember where you left off — even after you close the tab?<br />With Zustand’s <strong>persist middleware</strong>, it can:</p>
<pre><code class="lang-plaintext">import { create } from 'zustand'
import { persist } from 'zustand/middleware'

const useGardenStore = create(
  persist(
    (set) =&gt; ({
      plants: [],
      addPlant: (name) =&gt;
        set((state) =&gt; ({
          plants: [...state.plants, { id: Date.now(), name }]
        })),
    }),
    { name: 'garden-storage' }
  )
);
</code></pre>
<p>Now your plants (state) will be stored in <code>localStorage</code>, blooming right where you left them the next time you visit.</p>
<hr />
<h2 id="heading-why-developers-love-zustand">Why Developers Love Zustand</h2>
<p>Zustand feels <em>alive</em> — a quiet, self-maintaining garden of state.</p>
<ul>
<li><p><strong>Lightweight:</strong> Less than 1 KB gzipped</p>
</li>
<li><p><strong>Reactive:</strong> Updates only what’s necessary</p>
</li>
<li><p><strong>Minimal API:</strong> One store, simple syntax</p>
</li>
<li><p><strong>Async-ready:</strong> Works great with API calls and side effects</p>
</li>
</ul>
<p>It’s <strong>state management without the noise</strong> — just clean growth.</p>
<hr />
<h2 id="heading-in-the-end-growing-calmly-with-zustand">In the End: Growing Calmly with Zustand</h2>
<p>Managing state doesn’t have to feel like pruning a jungle.<br />With Zustand, it’s like tending a peaceful garden — plant what you need, nurture it as it grows, and trust the system to keep it thriving.</p>
<p>Once you experience the quiet simplicity of Zustand, you’ll wonder how you ever gardened with spreadsheets and dispatchers.</p>
]]></content:encoded></item><item><title><![CDATA[From Garden Shop to Web Apps]]></title><description><![CDATA[The Beginning: A Gardener with a Vision
Imagine you own a small garden shop. Every day, people visit you for plants — some want instant pick-ups, others want something fresh, and a few enjoy growing plants themselves.
You quickly realize:How you deli...]]></description><link>https://vidushisingla.xyz/from-garden-shop-to-web-apps</link><guid isPermaLink="true">https://vidushisingla.xyz/from-garden-shop-to-web-apps</guid><category><![CDATA[Next.js]]></category><category><![CDATA[React]]></category><category><![CDATA[react js]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[Front-end Development]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[TypeScript]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Wed, 01 Oct 2025 08:52:38 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759308639511/726d8100-7e1c-4101-8db6-3bb8ecaf5a26.gif" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-the-beginning-a-gardener-with-a-vision">The Beginning: A Gardener with a Vision</h3>
<p>Imagine you own a small <strong>garden shop</strong>. Every day, people visit you for plants — some want instant pick-ups, others want something fresh, and a few enjoy growing plants themselves.</p>
<p>You quickly realize:<br />How you deliver plants makes a big difference in customer happiness.</p>
<p>Similarly, when building websites with <strong>Next.js</strong>, how you deliver content to visitors is crucial. Developers refer to these strategies as <strong>CSR, SSR, SSG, and ISR</strong>. But in your garden shop, they’re just different ways of handing over plants.</p>
<hr />
<h2 id="heading-csr-do-it-yourself-plant-kits">CSR — “Do-It-Yourself Plant Kits”</h2>
<p>In the garden, you give customers <strong>soil, seeds, and a pot</strong>, and they grow the plant themselves.</p>
<p>On the web, the server sends only a <strong>blank page + JavaScript</strong>, and the <strong>browser builds everything</strong>.</p>
<pre><code class="lang-plaintext">// pages/dashboard.js (CSR in Next.js)
import { useEffect, useState } from "react";

export default function Dashboard() {
  const [data, setData] = useState(null);

  useEffect(() =&gt; {
    // Fetching happens in the browser
    fetch("/api/user")
      .then(res =&gt; res.json())
      .then(setData);
  }, []);

  if (!data) return &lt;p&gt;Loading...&lt;/p&gt;;
  return &lt;h1&gt;Welcome back, {data.name}&lt;/h1&gt;;
}
</code></pre>
<p>Best for <strong>dashboards, chats, and private apps</strong>.<br />First load is slower, but once loaded, it’s very interactive.</p>
<hr />
<h2 id="heading-ssr-freshly-picked-plants-on-the-spot">SSR — “Freshly Picked Plants on the Spot”</h2>
<p>In the garden: a customer asks for basil, you <strong>pick it fresh</strong> from the greenhouse, and hand it over.</p>
<p>On the web, the server <strong>builds HTML on request</strong> and sends it fresh every time.</p>
<pre><code class="lang-plaintext">// pages/news.js (SSR in Next.js)
export async function getServerSideProps() {
  const res = await fetch("https://api.example.com/news");
  const articles = await res.json();
  return { props: { articles } };
}

export default function News({ articles }) {
  return (
    &lt;div&gt;
      &lt;h1&gt;Fresh News&lt;/h1&gt;
      {articles.map(a =&gt; &lt;p key={a.id}&gt;{a.title}&lt;/p&gt;)}
    &lt;/div&gt;
  );
}
</code></pre>
<p>Great for <strong>news sites, stock tickers, or e-commerce product pages</strong>.<br />Heavy load if many people visit at once, since the server works all the time.</p>
<hr />
<h2 id="heading-ssg-plants-prepared-in-advance">SSG — “Plants Prepared in Advance”</h2>
<p>In the garden, you prepare <strong>100 pots of mint in the morning</strong> and place them in the shop. Customers get them instantly.</p>
<p>On the web, pages are <strong>pre-rendered at build time</strong> and served instantly.</p>
<pre><code class="lang-plaintext">// pages/blog/[id].js (SSG in Next.js)
export async function getStaticPaths() {
  const res = await fetch("https://api.example.com/posts");
  const posts = await res.json();
  const paths = posts.map(p =&gt; ({ params: { id: p.id.toString() } }));
  return { paths, fallback: false };
}

export async function getStaticProps({ params }) {
  const res = await fetch(`https://api.example.com/posts/${params.id}`);
  const post = await res.json();
  return { props: { post } };
}

export default function BlogPost({ post }) {
  return &lt;article&gt;&lt;h1&gt;{post.title}&lt;/h1&gt;&lt;p&gt;{post.content}&lt;/p&gt;&lt;/article&gt;;
}
</code></pre>
<p>Perfect for <strong>blogs, documentation, and landing pages</strong>.<br />Content updates only when you rebuild the app.</p>
<hr />
<h2 id="heading-isr-restocking-the-shelves">ISR — “Restocking the Shelves”</h2>
<p>In the garden: instead of preparing mint only once, you set a rule — restock <strong>every few hours</strong> to keep them fresh.</p>
<p>On the web, pages are <strong>pre-rendered once</strong>, then <strong>regenerated after a set time</strong>.</p>
<pre><code class="lang-plaintext">// pages/jobs.js (ISR in Next.js)
export async function getStaticProps() {
  const res = await fetch("https://api.example.com/jobs");
  const jobs = await res.json();

  return {
    props: { jobs },
    revalidate: 60, // Rebuild every 60 seconds
  };
}

export default function Jobs({ jobs }) {
  return (
    &lt;div&gt;
      &lt;h1&gt;Job Listings&lt;/h1&gt;
      {jobs.map(j =&gt; &lt;p key={j.id}&gt;{j.title}&lt;/p&gt;)}
    &lt;/div&gt;
  );
}
</code></pre>
<p>Best for <strong>job boards, catalogs, and event listings</strong>.<br />New content may take a short time to appear.</p>
<hr />
<h2 id="heading-the-balanced-garden-shop">The Balanced Garden Shop</h2>
<p>Running your garden shop taught you something: there’s no single “best” way.</p>
<ul>
<li><p>DIY kits for plant lovers → <strong>CSR</strong></p>
</li>
<li><p>Fresh picks for special requests → <strong>SSR</strong></p>
</li>
<li><p>Prepped plants for speed → <strong>SSG</strong></p>
</li>
<li><p>Regularly restocked plants → <strong>ISR</strong></p>
</li>
</ul>
<p>In the same way, <strong>Next.js lets you mix and match</strong>. Some pages are static, some are dynamic, some refresh on a schedule, and some are built entirely by the browser.</p>
<hr />
<h2 id="heading-closing-thought">🌼 Closing Thought</h2>
<p>Your garden isn’t just about plants — it’s about <strong>how you deliver them</strong>.</p>
<p>Your website isn’t just about content — it’s about <strong>how you render it</strong>.</p>
<p>With Next.js, you can balance CSR, SSR, SSG, and ISR like a skilled gardener balancing DIY kits, fresh picks, prepped plants, and restocks. The result: a website that’s fast, fresh, and tailored to what each visitor needs.</p>
]]></content:encoded></item><item><title><![CDATA[Micro-Frontends vs Traditional Frontends]]></title><description><![CDATA[Software architecture can feel abstract, but metaphors help. So let’s imagine your frontend as a garden.
At first, you only have a backyard. You plant a few tomatoes, maybe a rose bush, and water them with a friend. Life is simple. Everything fits in...]]></description><link>https://vidushisingla.xyz/micro-frontends-vs-traditional-frontends</link><guid isPermaLink="true">https://vidushisingla.xyz/micro-frontends-vs-traditional-frontends</guid><category><![CDATA[Microfrontend]]></category><category><![CDATA[React]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[System Architecture]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Mon, 29 Sep 2025 10:05:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759140301668/9bdad7ad-e03a-4e3c-a94d-534b76a7c3ad.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Software architecture can feel abstract, but metaphors help. So let’s imagine your frontend as a garden.</p>
<p>At first, you only have a backyard. You plant a few tomatoes, maybe a rose bush, and water them with a friend. Life is simple. Everything fits into that one cozy patch. That’s a <strong>traditional frontend</strong>: one codebase, one team, one deployment.</p>
<p>But what happens when your backyard becomes a park? Suddenly, you want a rose garden, a greenhouse, fruit trees, and a koi pond. You hire more gardeners. One insists on compost, another on hydroponics. They bump into each other, and a pest in the roses threatens the entire yard. Suddenly, one big patch isn’t working anymore.</p>
<p>That’s where <strong>micro-frontends</strong> come in: breaking your park into smaller, independent gardens, each tended by its own team.</p>
<hr />
<h2 id="heading-what-is-a-traditional-frontend">What Is a Traditional Frontend?</h2>
<p>A traditional frontend is a single, unified application. It works best when:</p>
<ul>
<li><p>Your product is small to medium-sized.</p>
</li>
<li><p>A single team (or small group) maintains it.</p>
</li>
<li><p>Features are tightly connected and share logic.</p>
</li>
</ul>
<p><strong>Benefits:</strong></p>
<ul>
<li><p>Easy to keep a consistent design and user experience.</p>
</li>
<li><p>Simple deployment—one build, one release pipeline.</p>
</li>
<li><p>Shared state and data flow are straightforward.</p>
</li>
</ul>
<p><strong>Drawbacks:</strong></p>
<ul>
<li><p>As the app grows, deployments slow down.</p>
</li>
<li><p>Coordination between teams gets messy.</p>
</li>
<li><p>A single bug can affect the entire app.</p>
</li>
</ul>
<p>In gardening terms, a tidy backyard is perfect when your needs are modest.</p>
<hr />
<h2 id="heading-what-is-a-micro-frontend">What Is a Micro-Frontend?</h2>
<p>A micro-frontend splits your frontend into <strong>smaller, self-contained applications</strong>, each focused on a specific domain or feature. Together, they form a seamless experience for the user.</p>
<p>Think of it as building a <strong>neighborhood park</strong> instead of one oversized backyard.</p>
<h3 id="heading-the-key-pieces-of-the-park">The Key Pieces of the Park</h3>
<ul>
<li><p><strong>Plots (Individual Apps):</strong> Each team manages its own micro-frontend (checkout, profile, search, etc.). They pick their own tools and ship independently.</p>
</li>
<li><p><strong>Paths and Fences (Integration Layer):</strong> Routing, navigation, and shared layout keep the park coherent. Fences prevent one team’s mess from spilling into another’s.</p>
</li>
<li><p><strong>Water Supply (Shared Services):</strong> Authentication, sessions, and APIs are like irrigation—shared infrastructure that everyone relies on.</p>
</li>
<li><p><strong>The Entrance (Shell App):</strong> The shell is the front gate that pulls everything together. It provides the layout, header, and glue code for loading micro-frontends.</p>
</li>
</ul>
<hr />
<h2 id="heading-why-split-the-garden-the-benefits-of-micro-frontends">Why Split the Garden? The Benefits of Micro-Frontends</h2>
<ul>
<li><p><strong>Autonomy and Speed:</strong> Teams can build and release independently.</p>
</li>
<li><p><strong>Scalability:</strong> New “plots” can be added without redesigning the entire system.</p>
</li>
<li><p><strong>Fault Isolation:</strong> One bug doesn’t crash the entire app.</p>
</li>
<li><p><strong>Flexibility:</strong> Teams can use different frameworks or tools if necessary.</p>
</li>
</ul>
<hr />
<h2 id="heading-where-the-weeds-hide-challenges-of-micro-frontends">Where the Weeds Hide: Challenges of Micro-Frontends</h2>
<ul>
<li><p><strong>Inconsistent Styles:</strong> Without a shared design system, the park looks mismatched.</p>
</li>
<li><p><strong>Duplicate Dependencies:</strong> Multiple bundles can slow down performance if not optimized.</p>
</li>
<li><p><strong>Shared Concerns:</strong> Authentication, analytics, and global state require careful planning.</p>
</li>
<li><p><strong>Operational Overhead:</strong> More repos, more pipelines, more deployment complexity.</p>
</li>
</ul>
<hr />
<h2 id="heading-when-to-choose-which-approach">When to Choose Which Approach</h2>
<ul>
<li><p><strong>Go traditional (one garden):</strong><br />  If you have a small product, a small team, and don’t expect rapid scaling.</p>
</li>
<li><p><strong>Go micro (many gardens):</strong><br />  If your app is large, your teams are many, and you need to release features independently without blocking each other.</p>
</li>
</ul>
<hr />
<h2 id="heading-conclusion-its-about-scale-not-fashion">Conclusion: It’s About Scale, Not Fashion</h2>
<p>Choosing micro-frontends isn’t about chasing trends. It’s about recognizing when your “garden” is too big for one team to manage. If your app is small, stick with a single frontend—it’s simpler and faster. If your app is sprawling and your teams are stepping on each other’s toes, it’s time to build a park with multiple gardens.</p>
<p>And just like a real park, the success of micro-frontends depends on shared paths, fences, and a consistent style that makes it feel like one coherent place.</p>
<p><em>In a future post, we’ll dive into the practical steps for implementing micro-frontends—using tools like Webpack Module Federation and single-spa—without losing the magic of the garden metaphor.</em></p>
]]></content:encoded></item><item><title><![CDATA[From Soil to Garden: How Next.js Grew from React]]></title><description><![CDATA[When you start gardening, the first thing you need is soil.That’s what React is — the soil where you can plant your UI components.
React gave developers the flexibility to grow anything: buttons, forms, and entire applications. But just like raw soil...]]></description><link>https://vidushisingla.xyz/from-soil-to-garden-how-nextjs-grew-from-react</link><guid isPermaLink="true">https://vidushisingla.xyz/from-soil-to-garden-how-nextjs-grew-from-react</guid><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Sun, 28 Sep 2025 12:30:20 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1759062588520/e67e59ec-d852-485b-aa43-4e09c9e8a516.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When you start gardening, the first thing you need is <strong>soil</strong>.<br />That’s what <strong>React</strong> is — the soil where you can plant your UI components.</p>
<p>React gave developers the flexibility to grow anything: buttons, forms, and entire applications. But just like raw soil, React didn’t come with pathways, irrigation, or a plan. You had to bring in your own <strong>tools</strong> (like React Router for navigation, Axios for data fetching, Webpack for bundling, etc.).</p>
<p>That worked fine for small pots. But when your garden grew bigger, managing it became exhausting.</p>
<hr />
<h2 id="heading-enter-nextjs-the-garden-around-the-soil">Enter Next.js: The Garden Around the Soil</h2>
<p>Next.js arrived as a gardener’s <strong>dream community garden</strong> built on React’s soil. It didn’t replace React; it simply added everything you needed to actually make your garden flourish:</p>
<ul>
<li><p><strong>File-based routing</strong> → Instead of manually laying stepping stones (React Router), each file in <code>pages/</code> is already a path through the garden.</p>
</li>
<li><p><strong>Pre-rendering (SSG/SSR)</strong> → Some plants are grown before visitors arrive (Static Generation), others are watered fresh daily (Server-side Rendering).</p>
</li>
<li><p><strong>API Routes</strong> → Your own compost bin for nutrients — no need for a separate backend for small tasks.</p>
</li>
<li><p><strong>Image optimization &amp; performance tweaks</strong> → Automatic irrigation, so your garden doesn’t dry out or overflow.</p>
</li>
</ul>
<hr />
<h2 id="heading-why-do-we-need-nextjs">Why Do We Need Next.js?</h2>
<p>React alone renders pages on the <strong>client side</strong>, meaning the browser receives minimal HTML and then builds everything using JavaScript. This leads to three challenges: <strong>SEO issues</strong> (search engines can’t always see your content), <strong>slower performance</strong> (large bundles delay first render), and <strong>extra setup work</strong> (you need separate tools for routing, SSR, and optimization). Next.js solves all of this by providing <strong>server-side rendering, static generation, file-based routing, built-in API routes, and performance optimizations</strong> out of the box. In other words, it takes React’s flexibility and turns it into a <strong>production-ready framework</strong> that’s fast, SEO-friendly, and scalable.</p>
<h2 id="heading-react-vs-nextjs-in-nature-terms">React vs Next.js in Nature Terms</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>React = Soil Only</td><td>Next.js = Garden</td></tr>
</thead>
<tbody>
<tr>
<td>Routing</td><td>Needs tools (React Router)</td><td>Built-in file-based paths</td></tr>
<tr>
<td>Rendering</td><td>Client-side only (seeds sprout when the visitor arrives)</td><td>Choose: Static, Server-side, or Client-side</td></tr>
<tr>
<td>SEO</td><td>Poor (plants hidden under soil until JS runs)</td><td>Great (plants visible right away)</td></tr>
<tr>
<td>API Support</td><td>Needs a separate backend</td><td>Has a compost bin (API routes)</td></tr>
<tr>
<td>Deployment</td><td>Manual setup</td><td>One-click hosting on Vercel</td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-why-this-matters">Why This Matters</h2>
<p>If React is where you <strong>experiment with planting seeds</strong>, then Next.js is where you <strong>build a full, flourishing garden</strong> that visitors can walk through easily.</p>
<p>React gave us the <strong>freedom</strong> to grow.<br />Next.js gave us the <strong>structure</strong> to scale.</p>
<p>Just like soil without sunlight can’t produce much, React without Next.js often struggles with SEO, performance, and routing. But when combined, they create a thriving ecosystem — the digital version of a lush green garden.</p>
<hr />
<p>So the next time you open a Next.js project, think of it like stepping into a well-prepared garden. The soil (React) is still there beneath your feet, but the pathways, irrigation, and compost bins (Next.js) are what make it bloom beautifully.</p>
<p>Do you want to learn more about these pathways, irrigation, or the bins? Let’s grow into this garden together! We will delve more into NextJS in our blog!</p>
]]></content:encoded></item><item><title><![CDATA[Story Time: Learning useRef, useMemo, and useCallback]]></title><description><![CDATA[In a quiet corner of a vibrant garden, a small girl tended to her plants every day. She knew that each plant required care in just the right way—some needed careful watering, some needed tracking, and some required consistent routines.
Managing a gar...]]></description><link>https://vidushisingla.xyz/story-time-learning-useref-usememo-and-usecallback</link><guid isPermaLink="true">https://vidushisingla.xyz/story-time-learning-useref-usememo-and-usecallback</guid><category><![CDATA[React]]></category><category><![CDATA[useState]]></category><category><![CDATA[useRef]]></category><category><![CDATA[useMemo]]></category><category><![CDATA[useCallback]]></category><category><![CDATA[components]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Wed, 24 Sep 2025 09:42:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1758706879509/5a512ff5-6559-4b2b-92c4-0956662d6219.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In a quiet corner of a vibrant garden, a small girl tended to her plants every day. She knew that each plant required care in just the right way—some needed careful watering, some needed tracking, and some required consistent routines.</p>
<p>Managing a garden this way is not so different from managing a React app. Just as she had her habits and tools, React provides hooks like <code>useRef</code>, <code>useMemo</code>, and <code>useCallback</code> to make handling values, computations, and functions efficient and predictable.</p>
<hr />
<p>As the morning sun rose, she noticed her tallest sunflower. Curious about how much it had grown, she marked its current height on a small stick.</p>
<p>Days passed, and whenever the sunflower grew taller, she added a new mark for the updated height. These marks didn’t affect the plant’s growth; they were simply references to track progress.</p>
<p>In React, <code>useRef</code> works the same way. It allows you to store a value across renders without triggering re-renders, whether you’re tracking DOM elements, storing mutable values, or keeping a reference for later use.</p>
<pre><code class="lang-plaintext">const plantHeight = useRef(0);
plantHeight.current = 15;
</code></pre>
<p>By midday, the girl moved to her rose bush. She had learned the perfect amount of water to give it based on the soil and the size of the plant. Instead of calculating this every time she watered, she kept the amount fixed until either the plant or the soil required a change.</p>
<p>Similarly, <code>useMemo</code> in React, memorizes the result of a computation and only recalculates it when its dependencies change. This saves effort and ensures that expensive calculations don’t run unnecessarily, keeping everything efficient and smooth.</p>
<pre><code class="lang-plaintext">const waterAmount = useMemo(() =&gt; soil.moisture * plant.size * 0.5, [plant.size, soil.moisture]);
</code></pre>
<p>As evening approached, she prepared her daily watering routine. She had perfected the steps over time, and she didn’t want to rewrite them every day. Instead, she followed the same routine unless the plant or soil conditions changed.</p>
<p>In React, <code>useCallback</code> serves this purpose. It memorizes a function and recreates it only when dependencies change, which is particularly useful when passing functions to child components. This way, the garden runs smoothly, and no unnecessary work is repeated.</p>
<pre><code class="lang-plaintext">const waterPlant = useCallback(() =&gt; console.log(`Watering ${plant.name} with ${soil.moisture} moisture`), [plant.name, soil.moisture]);
</code></pre>
<hr />
<h3 id="heading-quick-reference-table">Quick Reference Table</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Hook</td><td>Garden Analogy</td><td>React Purpose</td><td>Example Use Case</td></tr>
</thead>
<tbody>
<tr>
<td><code>useRef</code></td><td>Mark plant height (add new marks as it grows)</td><td>Keep a value across renders without re-rendering</td><td>Tracking DOM elements or mutable values</td></tr>
<tr>
<td><code>useMemo</code></td><td>Fixed watering amount</td><td>Memorize expensive computations</td><td>Calculating derived state</td></tr>
<tr>
<td><code>useCallback</code></td><td>Reusable watering routine</td><td>Memorize functions to avoid re-creation</td><td>Passing stable callbacks to child components</td></tr>
</tbody>
</table>
</div><hr />
<p>By the end of the day, the small girl’s garden thrived. Her careful habits—marking heights, fixing watering amounts, and following reusable routines—kept every plant growing beautifully.</p>
<p>In the same way, using <code>useRef</code>, <code>useMemo</code>, and <code>useCallback</code> wisely allows your React apps to run efficiently, stay organized, and “bloom” reliably, just like a well-tended garden.</p>
]]></content:encoded></item><item><title><![CDATA[The Secret Sauce of Growth – Functions in Context]]></title><description><![CDATA[Today, we won’t waste much time — let’s get straight to the exciting part: actions in context! 🚀
Think of functions in context as the garden tools in our tree analogy.
The water (our data) flows effortlessly through the tree via context, reaching ev...]]></description><link>https://vidushisingla.xyz/the-secret-sauce-of-growth-functions-in-context</link><guid isPermaLink="true">https://vidushisingla.xyz/the-secret-sauce-of-growth-functions-in-context</guid><category><![CDATA[React]]></category><category><![CDATA[components]]></category><category><![CDATA[ReactHooks]]></category><category><![CDATA[useContext]]></category><category><![CDATA[useEffect]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Sat, 20 Sep 2025 06:27:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1758348916158/4231a0b8-4787-443b-a6ae-b719a048feb4.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today, we won’t waste much time — let’s get straight to the exciting part: <strong>actions in context!</strong> 🚀</p>
<p>Think of <strong>functions in context</strong> as the garden tools in our tree analogy.</p>
<p>The water (our data) flows effortlessly through the tree via context, reaching every branch and leaf. But sometimes, the tree needs more than just water — it needs <strong>actions</strong>: pruning a branch, planting a new one, or watering a specific spot. That’s exactly what these tools (functions) do.</p>
<p>By placing these functions in context, every part of the tree — whether it’s a branch, leaf, or flower — has access to the same set of tools. You don’t have to carry a shovel and watering can to each plant (no more prop drilling!). Instead, everything is stored in one central shed (the context), ready to use whenever and wherever it’s needed.</p>
<p>In our last article, we set up a <strong>context</strong> for our parent component, <code>Tree</code>, along with its children — <code>Branch</code>, <code>Leaf</code>, and so on. Let’s revisit that context!</p>
<p>Remember the <strong>button</strong> we added? Clicking it was supposed to create a new branch. To make this happen, we defined a <strong>function inside our context</strong>, which interacts with the shared state. Now, let’s break down this function step by step and understand <strong>how it works</strong> to grow our tree across all components dynamically.</p>
<p>To add a new branch dynamically, we create a function inside our context — think of it as a <strong>garden tool</strong> that lets us prune, plant, or nurture any part of the tree.</p>
<pre><code class="lang-plaintext">export const TreeProvider = ({ children }) =&gt; {
  const [tree, setTree] = useState(initialTree);

  const addBranch = (newBranch) =&gt; {
    setTree({
      ...tree,
      branches: [...(tree.branches || []), newBranch]
    });
  };

  return (
    &lt;TreeContext.Provider value={{ tree, addBranch }}&gt;
      {children}
    &lt;/TreeContext.Provider&gt;
  );
};
</code></pre>
<p>Here’s what’s happening:</p>
<ol>
<li><p><code>useState</code> keeps track of the tree — our central water system.</p>
</li>
<li><p><code>addBranch</code> - It acts as a gardening tool, adding a new branch to the tree without disturbing the existing ones.</p>
<p> <strong>Spreading the existing tree</strong>:</p>
<pre><code class="lang-plaintext"> ...tree
</code></pre>
<p> This ensures that all current branches, leaves, and flowers stay intact. Think of it as keeping the existing tree healthy while adding something new.</p>
<p> <strong>Adding a new branch</strong>:</p>
<pre><code class="lang-plaintext"> branches: [...(tree.branches || []), newBranch]
</code></pre>
<p> Here, we either take the existing <code>branches</code> array (or an empty array if none exists) and append the <code>newBranch</code>. In our garden analogy, this is like planting a new branch without uprooting the old ones.</p>
<p> <strong>Updating the state</strong>:</p>
<pre><code class="lang-plaintext"> setTree(...)
</code></pre>
<p> This is the “watering” step — it triggers React to re-render all components consuming this context, so the new branch instantly appears wherever it’s needed.</p>
</li>
<li><p>By passing both <code>tree</code> and <code>addBranch</code> through the <strong>provider</strong>, every component can access the tree and the tool whenever needed — no prop drilling required.</p>
</li>
</ol>
<p>And just like that, it all comes together! The context flows like water, the functions act as handy garden tools, and suddenly, managing data across your components feels effortless. No more prop drilling, no more messy state juggling — just a clean, growing tree where every branch, leaf, and flower knows exactly what it needs.</p>
<p>But before we wrap up today, a quick teaser: in the next article, we’ll explore three powerful React hooks — <code>useRef</code>, <code>useMemo</code>, and <code>useCallback</code>. These are like <strong>special tools in our garden shed</strong>: <code>useRef</code> lets us tag and keep track of specific branches or flowers, <code>useMemo</code> helps us optimize heavy calculations like counting leaves, and <code>useCallback</code> ensures our action tools (functions) are always ready without unnecessary re-creation.</p>
<p>Get ready to take our tree to the next level — smarter, faster, and more efficient!</p>
]]></content:encoded></item><item><title><![CDATA[Let's Connect the Garden! - Coding with useContext]]></title><description><![CDATA[In our previous blog, we explored useContext and how it allows water (data) to flow seamlessly through the entire tree without losing its essence.
However, when I first examined code snippets like these, I often struggled to connect the dots and trul...]]></description><link>https://vidushisingla.xyz/lets-connect-the-garden-coding-with-usecontext</link><guid isPermaLink="true">https://vidushisingla.xyz/lets-connect-the-garden-coding-with-usecontext</guid><category><![CDATA[React]]></category><category><![CDATA[js]]></category><category><![CDATA[useContext]]></category><category><![CDATA[coding]]></category><category><![CDATA[coding challenge]]></category><category><![CDATA[components]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Wed, 17 Sep 2025 07:00:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1758019064373/a5646434-0eb0-4170-949a-2ff0aeb8c219.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In our previous blog, we explored <strong>useContext</strong> and how it allows water (data) to flow seamlessly through the entire tree without losing its essence.</p>
<p>However, when I first examined code snippets like these, I often struggled to connect the dots and truly grasp the flow. So, in this article, let’s go a step further — from concept to code — and break down how it all works in practice.</p>
<p>Since <strong>useContext</strong> is all about accessing data, we’ll begin by setting up some example data. And because our analogy revolves around a tree, our dataset will be… a tree itself! At the top level, we’ll have a <strong>branch</strong> as the first key. Its value will be an object containing an <strong>id</strong> and a <strong>leaf</strong>. The <strong>leaf</strong> itself will hold another object, which finally expands into a <strong>flower</strong>:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758015799114/9cabc69e-94ae-4817-9ee0-2574c8f5181e.png" alt class="image--center mx-auto" /></p>
<p>Now that we have our tree structure, the next step is to set up some React components and files that we’ll use throughout the example. To keep things organized, we’ll create two folders: <strong>components</strong> and <strong>context</strong>. Alongside these, we’ll also have our main files — <strong>App.js</strong> and <strong>index.js</strong> — to tie everything together.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1758016099781/7e412c42-6d2a-453a-ad7e-8b69ddb50921.png" alt class="image--center mx-auto" /></p>
<p>First, let’s establish the context. This would be our store, where all the variables of functions would be declared, and would be accessible from!</p>
<ol>
<li><h3 id="heading-1-importing-the-essentials">1. Importing the essentials</h3>
<p> First, we’ll bring in the React libraries we need — <code>createContext</code>, <code>useContext</code>, and <code>useState</code>:</p>
<pre><code class="lang-plaintext"> import React, { createContext, useContext, useState } from "react";
</code></pre>
</li>
<li><h3 id="heading-declaring-the-context-and-initial-tree">Declaring the context and initial tree</h3>
<p> Next, we declare our <strong>context</strong> and an initial tree structure (from the data model we defined earlier):</p>
<pre><code class="lang-plaintext"> const TreeContext = createContext();

 const initialTree = {
   branch: {
     id: 1,
     leaf: {
       flower: "🌸"
     }
   }
 };
</code></pre>
<h3 id="heading-3-creating-the-treeprovider">3. Creating the TreeProvider</h3>
<p> Now comes the core piece: the <strong>TreeProvider</strong>.<br /> Its role is to ensure that our data (the tree) is accessible throughout the React component hierarchy. In other words, it’s the “water source” that supplies data everywhere. Inside our <code>TreeProvider</code>, we use the <code>useState</code> hook to manage the tree’s data. This allows us to not only store the initial tree but also update it dynamically whenever needed. By wrapping our children with <code>TreeContext.Provider</code> and passing the <code>tree</code> (along with any helper functions like <code>addBranch</code>) into its <code>value</code>, we make the data available to every component within this provider’s scope. In short, the provider acts as the central source, ensuring that all child components can seamlessly access and interact with the tree without the hassle of prop drilling.</p>
<pre><code class="lang-plaintext"> export const TreeProvider = ({ children }) =&gt; {

   const [tree, setTree] = useState(initialTree);

   // Example function to add a branch (we’ll define this further later)
   const addBranch = (newBranch) =&gt; {
     setTree({ ...tree, ...newBranch });
   };

   return (
     &lt;TreeContext.Provider value={{ tree, addBranch }}&gt;
       {children}
     &lt;/TreeContext.Provider&gt;
   );
 };
</code></pre>
<h3 id="heading-4-making-the-context-reusable">4. Making the context reusable</h3>
<p> To simplify context usage, we’ll create a custom hook that lets any component access our tree directly:</p>
<pre><code class="lang-plaintext"> export const useTree = () =&gt; useContext(TreeContext);
</code></pre>
<p> With this setup, our tree context is now <strong>ready to be shared across the app</strong>.</p>
</li>
</ol>
<p>For starters, we set up an App.js, from where the Provider will wrap our first component, &lt;Tree/&gt;</p>
<pre><code class="lang-plaintext">import React from "react";
import { TreeProvider } from "./context/TreeContext";
import Branch from "./components/Branch";

const App = () =&gt; {
  return (
    &lt;TreeProvider&gt;
        &lt;Branch /&gt;
    &lt;/TreeProvider&gt;
  );
};

export default App;
</code></pre>
<p>Further, we go deeper in our tree and use our recently created context inside the &lt;Branch/&gt; component.</p>
<pre><code class="lang-plaintext">import React from "react";
import { useTree } from "../context/TreeContext";
import Leaf from "./Leaf";

const Branch = () =&gt; {
  const { tree, addBranch } = useTree();
  const branches = tree.branches;

  return (
    &lt;div&gt;
      &lt;h2&gt;Branches&lt;/h2&gt;
      &lt;button onClick={addBranch}&gt;➕ Add Branch&lt;/button&gt;
      {Object.entries(branches).map(([key, branch]) =&gt; (
        &lt;div key={key}&gt;
          &lt;h3&gt;{key} (id: {branch.id})&lt;/h3&gt;
          &lt;Leaf leaf={branch.leaf} /&gt;
        &lt;/div&gt;
      ))}
    &lt;/div&gt;
  );
};

export default Branch;
</code></pre>
<p>This is a simple execution of our <strong>Branch Component</strong> — let’s break down what’s happening here:</p>
<ol>
<li><p><strong>Importing the context</strong> <code>import { useTree } from "../context/TreeContext";</code></p>
<p> We bring in our custom hook, <code>useTree</code>, which gives us direct access to the context we created earlier.</p>
</li>
<li><p><strong>Extracting values from context</strong> <code>const { tree, addBranch } = useTree();</code></p>
<p> Here, we deconstruct the context to get both the <code>tree</code> data and the <code>addBranch</code> function.</p>
</li>
<li><p><strong>Adding a new branch</strong> <code>&lt;button onClick={addBranch}&gt;➕ Add Branch&lt;/button&gt;</code></p>
<p> This button will trigger the <code>addBranch</code> function whenever clicked, allowing us to dynamically grow our tree (we’ll explore this in detail later).</p>
</li>
<li><p><strong>Using the tree data</strong></p>
<p> Finally, we can access the <code>tree</code> object to pull out its branches, leaves, and IDs for rendering inside our component.</p>
</li>
</ol>
<p>Finally, the Leaf and Flower components are nested inside the Branch components.</p>
<pre><code class="lang-plaintext">import React from "react";
import Flower from "./Flower";

const Leaf = ({ leaf }) =&gt; {
  return (
    &lt;div&gt;
      &lt;h3&gt;Leaf&lt;/h3&gt;
      &lt;Flower flower={leaf.flower} /&gt;
    &lt;/div&gt;
  );
};

export default Leaf;
</code></pre>
<pre><code class="lang-plaintext">import React from "react";

const Flower = ({ flower }) =&gt; {
  return (
    &lt;div}&gt;
      &lt;h4&gt; Flower: {flower}&lt;/h4&gt;
    &lt;/div&gt;
  );
};

export default Flower;
</code></pre>
<p>You might be wondering — why did we use <strong>props</strong> for passing down the leaf and flower instead of putting them into the context? To answer this, let’s return to our <strong>tree analogy</strong>.</p>
<p>Water is essential for every part of the tree, so it flows uniformly throughout — just like our context data. But what about byproducts of the soil that are only useful to a specific part, say the stem? We wouldn’t sprinkle those byproducts everywhere because not all parts need them, and even if we tried, extracting them would be unnecessarily complicated.</p>
<p>Similarly, in React, not all data belongs in context. Some values (like a specific leaf or flower) are only relevant to the immediate child component. In such cases, it’s simpler and cleaner to pass them as <strong>props</strong> rather than pushing everything through context.</p>
<p>That’s all for today! We’ve taken our first big steps into coding with <code>useContext</code> and building our tree. Next time, we’ll add a fun little function to actually make our tree grow. Until then — keep your roots strong and your branches reaching out!!</p>
]]></content:encoded></item><item><title><![CDATA[From Roots to Branches to the Leaves: Growing with useContext]]></title><description><![CDATA[In our last article, we discussed gardening — how specific conditions are required to plant a particular type of plant, just as useEffect helps React components respond to changes in their environment. Some plants require daily water intake, while so...]]></description><link>https://vidushisingla.xyz/from-roots-to-branches-to-the-leaves-growing-with-usecontext</link><guid isPermaLink="true">https://vidushisingla.xyz/from-roots-to-branches-to-the-leaves-growing-with-usecontext</guid><category><![CDATA[useEffect]]></category><category><![CDATA[React]]></category><category><![CDATA[ReactHooks]]></category><category><![CDATA[useEffect hook]]></category><category><![CDATA[useContext]]></category><category><![CDATA[hooks]]></category><category><![CDATA[Props in reactjs]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Mon, 15 Sep 2025 14:54:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1757948018559/8cd8187d-74cf-4863-9312-094f7b077829.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In our last article, we discussed gardening — how specific conditions are required to plant a particular type of plant, just as <strong>useEffect</strong> helps React components respond to changes in their environment. Some plants require daily water intake, while some require weekly water, and others only require it once.</p>
<p>Imagine a huge garden with 4–5 trees, some plants, and grass spread all around. Now, think about watering it — but with a twist. Instead of pouring water directly at the base, you can only water from the top, say, the leaves. The water droplets then have to pass downward — from leaves to branches, branches to the stem, and finally reach the roots. But here’s the problem: this method of watering can <strong>lead to a loss of water in both quality and quantity</strong>. Since the droplets take time to flow through the plant’s veins, they can deteriorate due to <strong>external factors</strong> (like sunlight evaporating them) or <strong>internal factors</strong> (like leakage along the way).</p>
<p>The same thing happens with <strong>props in React components</strong>. When data is passed down through multiple layers, it can get messy, harder to track, and sometimes even lose relevance by the time it reaches the component that actually needs it. This leads to a very fascinating term - prop drilling!</p>
<p>Imagine we have a <strong>Plant component</strong> that holds everything the plant needs: Water, Sunlight, Chlorophyll, and Minerals. The <code>Plant</code> component passes these props to its child component <code>Trunk</code>. The <code>Trunk</code> passes them further down to <code>Branches</code>, then <code>Leaves</code> and <code>Roots</code>. Finally, this can even go deeper into the <code>Soil</code> layer.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1757932097019/7fa9600a-1555-4dad-ad32-d1ace1cff2ad.png" alt class="image--center mx-auto" /></p>
<p>Here, each component has to carry the same props — even if it doesn’t directly use them — just so the next layer can get access. This is the exact problem with <strong>prop drilling</strong>.</p>
<p>“In <strong>React</strong>, <em>prop drilling</em> refers to the process of passing data from a <strong>top-level component</strong> down to deeply nested <strong>child components</strong> by passing props <strong>through every intermediary component</strong>, even if those intermediaries don’t directly use the data.”</p>
<p>It happens because React only allows data flow <strong>top-down (unidirectional)</strong> via props.</p>
<p>So how do we curb prop drilling? How do we ensure props are managed in a cleaner, more organized way while preserving the originality and essence of our data inside React components? The answer lies in React’s <code>useContext</code> hook, which allows us to share state seamlessly across the component tree without the hassle of manual prop passing.</p>
<p>Let’s circle back to our gardening parallel. Earlier, we imagined water flowing strictly from the top down through the plant, but that’s not how nature really works. In reality, when the source of water—be it a sprinkler or rainfall—appears, every part of the plant engages with it directly. The leaves soak it in, the branches get refreshed, the stem absorbs it, and even the soil drinks from the same source. Everything connects straight to the origin, without relying on a single pathway.</p>
<p>React mirrors this behavior with a central store. Instead of forcing props to drip down layer by layer (like our earlier top-down flow), we set up a single source of truth—using tools like <code>useContext</code> —where data lives at the origin. Just like the garden, every component can directly tap into that source whenever it needs nourishment.</p>
<p>The next big question is: how do we actually build this store? How do we access it, and how do we make our components consume the data from it? This is where React’s <code>useContext</code> hook comes into play. Let’s start by looking at the basic syntax of <code>useContext</code> and how we can use it across different components.</p>
<ol>
<li><p>We inject the context into our React components by using -</p>
<p> <code>import { createContext, useContext } from "react";</code></p>
</li>
<li><p>Then we create our context -</p>
<p> <code>const ThemeContext = createContext();</code></p>
</li>
<li><p>Wrapping our components with the Provider, which would help us access the context -</p>
<p> <code>&lt;ThemeContext.Provider value={theme}&gt;</code></p>
<p> <code>&lt;Layout/&gt;</code></p>
<p> <code>&lt;/ThemeContext.Provider&gt;</code></p>
</li>
<li><p>And later on in the child components, use the context created.</p>
<p> <code>const theme = useContext(ThemeContext); return</code></p>
<p> <code>Current Theme: {theme}</code></p>
</li>
</ol>
<p>When you went through the points, a bunch of questions must have spiraled through your head: <em>What is a Provider? What is a store? What are</em> <code>createContext</code> and <code>useContext</code>?</p>
<p>When we talk about <code>createContext</code>, think of it as setting up a water tank for our garden. It’s the container where our shared data—the water—will live. By itself, the tank doesn’t water the plants, but it defines the store, the single source of truth for our data.</p>
<p>Next comes the <strong>Provider</strong>. This is like connecting a sprinkler system or opening up the rain clouds. The Provider’s job is to distribute the water (data) to every plant (component) within its reach. Any part of the garden under the sprinkler is now able to receive nourishment.</p>
<p>Now, here’s where <strong>useContext</strong> comes in. Each part of the plant—be it the leaves, branches, stem, or even the soil—directly absorbs the water falling on it. Similarly, any React component under the Provider can call <code>useContext</code> to directly access the data from the store. No middle layers are needed to pass water around, just like no unnecessary prop drilling is required in React.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Concept</td><td>Gardening Analogy</td><td>React Functionality</td></tr>
</thead>
<tbody>
<tr>
<td><code>createContext</code></td><td>Water tank</td><td>Creates a store to hold shared data</td></tr>
<tr>
<td>Provider</td><td>Sprinkler system / opening rain clouds</td><td>Distributes data from the store to all nested components</td></tr>
<tr>
<td><code>useContext</code></td><td>The plant absorbs water directly</td><td>Component directly consumes data from the store without props</td></tr>
</tbody>
</table>
</div><p>It might seem a bit overwhelming at first, but as we dig deeper, you’ll discover just how powerful and organized it makes your React components. In our next blog, we’ll roll up our sleeves, create a live store, and show how to effortlessly share its data across multiple components.</p>
]]></content:encoded></item><item><title><![CDATA[Let's grow a garden together! - Nature's useEffect.]]></title><description><![CDATA[Planning a garden is no small task—every plant has its own unique needs: one may thrive in abundant sunlight, another may demand constant water, while yet another might rely on the gentle touch of the wind. Each element must be considered together, a...]]></description><link>https://vidushisingla.xyz/lets-grow-a-garden-together-natures-useeffect</link><guid isPermaLink="true">https://vidushisingla.xyz/lets-grow-a-garden-together-natures-useeffect</guid><category><![CDATA[useEffect]]></category><category><![CDATA[React]]></category><category><![CDATA[components]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[components in react]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Sun, 07 Sep 2025 14:26:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1757064702136/a9eae491-4457-41a3-a535-5e1776ed06a2.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Planning a garden is no small task—every plant has its own unique needs: one may thrive in abundant sunlight, another may demand constant water, while yet another might rely on the gentle touch of the wind. Each element must be considered together, as the growth of one is never separate from the rest.</p>
<p>Some plants require daily water, while others need it only once a month, and some patiently wait for the seasonal rains. A few flowers open beautifully under sunlight, while others shrink away from it. The gardener doesn’t treat them all the same—each plant is tended to at its own pace, in its own rhythm.</p>
<p>React works much the same way with <code>useEffect</code>. Think of it as the gardener of your component. Some effects must run every time, like daily watering. Some run only once, like planting a seed at the start. Others wait until the right condition changes—like rain arriving after a long summer. Each effect listens, responds, and nurtures the component, just as a gardener listens to the silent needs of their plants.</p>
<p>For example, roses need water every single day. Instead of remembering to water them manually, the gardener might set up a system so that with the arrival of each new day, the roses are automatically refreshed with water. React gives us something similar to <code>useEffect</code>. If we want a particular piece of code to run every time our component renders, we place it inside <code>useEffect</code> without a dependency array. Just like the gardener’s daily watering system, React ensures the effect is triggered on every render.</p>
<p><code>useEffect(() =&gt; {</code></p>
<p><code>console.log("Watering the roses 🌹 (runs on every render)");</code></p>
<p><code>});</code></p>
<p>Now, not every action in a garden happens daily. Take sowing seeds, for example—you only do it once when you start the garden. The gardener doesn’t keep planting the same seed again and again. In React, this is like using <code>useEffect</code> with an empty dependency array <code>[]</code>. It tells React: <em>‘run this effect only once, when the component first mounts, and never again.’</em></p>
<p><code>useEffect(() =&gt; {</code></p>
<p><code>console.log("🌱 Sowing the seeds (runs only once when component mounts)");</code></p>
<p><code>}, []);</code></p>
<p>Some flowers don’t need daily watering or one-time sowing—they wait for the sunlight to change. On a cloudy day, they stay still, but when the sun shines bright, they open up in full bloom. In React, this is like using <code>useEffect</code> with a dependency array. The effect doesn’t run all the time, only when a specific value changes.</p>
<p><code>useEffect(() =&gt; {</code></p>
<p><code>console.log(Flowers react to sunlight: ${sunlight} ☀️);</code></p>
<p><code>}, [sunlight]);</code></p>
<p>A small summary of what we understood so far!</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Garden Action</td><td>Frequency</td><td>React <code>useEffect</code> Equivalent</td><td>Example Code Trigger</td></tr>
</thead>
<tbody>
<tr>
<td>Watering roses daily</td><td>Every single day</td><td>Runs on <strong>every render</strong> (no dependency array)</td><td><code>useEffect(() =&gt; {...});</code></td></tr>
<tr>
<td>Sowing seeds</td><td>Only once, at the beginning</td><td>Runs <strong>once on mount</strong> (<code>[]</code>)</td><td><code>useEffect(() =&gt; {...}, []);</code></td></tr>
<tr>
<td>Flowers reacting to sunlight</td><td>Only when sunlight changes</td><td>Runs <strong>when dependency changes</strong> (<code>[sunlight]</code>)</td><td><code>useEffect(() =&gt; {...}, [sunlight]);</code></td></tr>
</tbody>
</table>
</div><p>Doesn’t this seem simple enough? A gardening task, something so natural and intuitive, mirrors how React <code>useEffect</code> works. By thinking of it as watering daily, sowing seeds once, or responding to sunlight changes, the logic behind dependencies suddenly feels less intimidating and more practical.</p>
<p>And this is just one piece of React’s powerful hook system. In our next article, we’ll step into <code>useContext</code> a hook that many developers both fear and love. Where <code>useEffect</code> is about timing and conditions, <code>useContext</code> is about <em>connection</em>: sharing values across components without having to pass props through every layer.</p>
<p>Stay tuned—we’ll uncover how <code>useContext</code> works, why it’s so useful, and how to overcome the fear around it.</p>
]]></content:encoded></item><item><title><![CDATA[From Calm Skies to Colorful States: Learning useState in React]]></title><description><![CDATA[It rained this evening, and as I sipped my tea under the open sky, I watched the colors shift—sometimes glowing, fading, changing completely as the wind carried the clouds. It felt calm, alive, and endlessly beautiful.
But then I wondered—what if the...]]></description><link>https://vidushisingla.xyz/from-calm-skies-to-colorful-states-learning-usestate-in-react</link><guid isPermaLink="true">https://vidushisingla.xyz/from-calm-skies-to-colorful-states-learning-usestate-in-react</guid><category><![CDATA[useState]]></category><category><![CDATA[hooks in react]]></category><category><![CDATA[React]]></category><category><![CDATA[JSX]]></category><category><![CDATA[Functional Programming]]></category><category><![CDATA[modularity]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Thu, 04 Sep 2025 10:08:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756965938342/8c81a9ce-8786-4f8d-9309-3716aabc6da3.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>It rained this evening, and as I sipped my tea under the open sky, I watched the colors shift—sometimes glowing, fading, changing completely as the wind carried the clouds. It felt calm, alive, and endlessly beautiful.</p>
<p>But then I wondered—what if the sky <strong>couldn’t change its colors</strong>? What if once the day began, the sky stayed the same until the next day? No gentle shifts with the wind, no golden hues at sunset, no rainbow after the rain. Just one fixed canvas, locked in place.</p>
<p>That’s how <strong>functional components in React</strong> used to be. Before 2019, when <strong>hooks didn’t exist</strong>, function components were only capable of <strong>rendering JSX [ “</strong>JSX (JavaScript XML) is a syntax extension for JavaScript that allows you to write HTML-like code inside your JavaScript.” <strong>]</strong>. They could display whatever <strong>props</strong> were passed down to them, but they had <strong>no state of their own</strong>. No matter what happened—wind, rain, or sunlight—their output stayed fixed until the parent re-rendered them.</p>
<p>A sky that cannot change with the weather… what a sad, colorless world that would be.</p>
<p>But then came <strong>Hooks!</strong> With hooks, function components could finally <strong>hold state</strong> and react to changes around them. <strong>Hooks are built-in functions in React that allow functional components to access core features like state, lifecycle events, and context.</strong> They were introduced in <strong>React 16.8 (2019)</strong> to give functional components the same power as class components—without the added complexity and boilerplate that classes require.</p>
<p>The first and most powerful of these is <code>useState</code>. useState is like the color bucket of the sky—it remembers the current shade, and whenever the environment changes, React updates the view with a new one. Red shifts to orange, orange to yellow, yellow to green, and so on! Let’s delve into this deeper!</p>
<p>Imagine you’re building a <code>&lt;Cloud&gt;</code> component—a simple cloud shape with a button inside it. The goal is that whenever the button is pressed, the cloud’s color should change. Without hooks, the component is <strong>read-only</strong>. The <code>&lt;Cloud&gt;</code> cannot manage its own color internally. To make it dynamic, it would need <strong>props from a parent component</strong>, along with a <strong>callback function</strong> to request a color change. Without this parent-managed state, the cloud <strong>cannot alter its color on its own</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756980115764/a29d8754-b072-42f5-9ec8-96e733ab6447.png" alt class="image--center mx-auto" /></p>
<p>Imagine the same <code>&lt;Cloud&gt;</code> component, but now we can use <strong>hooks</strong>. With the <code>useState</code> hook, the cloud can <strong>manage its own color internally</strong>, without relying on a parent component.</p>
<ul>
<li><p>You declare a <strong>state variable</strong> for the color inside the <code>&lt;Cloud&gt;</code> component.</p>
</li>
<li><p>When the button is pressed, you simply <strong>update the state</strong>, and React automatically <strong>re-renders the cloud</strong> with the new color.</p>
</li>
<li><p>No need for props, no need for a parent callback, no extra boilerplate—everything is <strong>self-contained</strong>.</p>
</li>
<li><p><code>const [color, setColor] = React.useState("blue");</code> - With every click, the setColor function can be called, and the color of the cloud can change within!</p>
</li>
</ul>
<p>Hooks are like giving the cloud its own <strong>paint bucket</strong>. Before, it had to ask its parent for a new color each time. Now, it can just dip its own brush and change color instantly whenever it wants.</p>
]]></content:encoded></item><item><title><![CDATA[Digital Toolkit vs Pencil Box]]></title><description><![CDATA[When I first started learning React, I felt like an artist deciding which tools to use. Should I stick to the traditional toolkit or switch to the modern digital app? That’s exactly what the difference between Class Components and Function Components...]]></description><link>https://vidushisingla.xyz/digital-toolkit-vs-pencil-box</link><guid isPermaLink="true">https://vidushisingla.xyz/digital-toolkit-vs-pencil-box</guid><category><![CDATA[Functional Programming]]></category><category><![CDATA[classes]]></category><category><![CDATA[class components]]></category><category><![CDATA[React]]></category><category><![CDATA[hooks]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Wed, 03 Sep 2025 17:29:04 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756920450688/dc6c057b-6c79-48bd-bc40-2834c64e473f.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When I first started learning React, I felt like an artist deciding which tools to use. Should I stick to the <strong>traditional toolkit</strong> or switch to the <strong>modern digital app</strong>? That’s exactly what the difference between <strong>Class Components</strong> and <strong>Function Components</strong> feels like.</p>
<hr />
<h2 id="heading-the-traditional-way-class-components">The Traditional Way – Class Components</h2>
<p>Imagine sitting at a desk, ready to draw. In front of you is a <strong>pencil box filled with tools</strong>: pencils, erasers, sharpeners, a ruler, maybe even a compass.</p>
<p>Every time you want to add detail, you reach for a different tool.</p>
<ul>
<li><p>Want to shade? Pick a pencil.</p>
</li>
<li><p>Want to fix a mistake? Grab the eraser.</p>
</li>
<li><p>Want a circle? Use the compass.</p>
</li>
</ul>
<p>It works, no doubt. But it feels <strong>heavy and procedural</strong>. You’re constantly managing tools, keeping track of steps, and making sure you don’t misplace anything.</p>
<p>This is what <strong>Class Components</strong> are like in React. You get structure, built-in methods, and lifecycle hooks, but there’s more overhead. Every class component requires a <strong>constructor</strong> for initializing state, explicit use of <code>this</code> to access props and methods, and lifecycle methods like <code>componentDidMount</code>, <code>componentDidUpdate</code>, and <code>componentWillUnmount</code> to manage side effects. Updating the state involves - <code>this.setState()</code>, merging the new state with the existing state in a controlled manner. While class components provide a <strong>clear separation of concerns</strong> and are fully capable of managing complex UI and stateful logic, they tend to be more <strong>verbose and rigid</strong>!</p>
<hr />
<h2 id="heading-the-modern-way-function-components">The Modern Way – Function Components</h2>
<p>Now, imagine opening an iPad with a stylus. Suddenly, you don’t need a separate eraser, compass, or sharpener. Everything you need—brushes, colors, undo/redo, even layers—is right there in one place.</p>
<p>If you want to try something new, just switch tools with a tap. No fumbling, no extra setup. It feels <strong>lighter, faster, and modern</strong>.</p>
<p>This is what <strong>Function Components with Hooks</strong> are like. They give you all the power of React—state, side effects, reusability—without the weight of class syntax and lifecycle methods. React has exciting hooks, which are like a great assist while coding complex logic. Function components are <strong>lighter, more modular, and highly reusable</strong>, making them the modern standard for building React applications.</p>
<hr />
<h2 id="heading-which-should-you-choose">Which Should You Choose?</h2>
<p>Both approaches let you create beautiful art. But while traditional tools (Class Components) still work, most artists today prefer the iPad (Function Components). They’re <strong>simpler, more flexible, and the recommended way forward in React</strong>.</p>
<p>So the next time you sit down to “draw” with React, ask yourself:<br />Do you want the <strong>pencil box</strong> or the <strong>digital canvas</strong>?</p>
]]></content:encoded></item><item><title><![CDATA[Today we draw a tree - One Component at a Time!]]></title><description><![CDATA[Nature is full of lessons if we take a moment to observe. A tree, for example, grows gracefully from a single seed into a complex system of roots, a sturdy trunk, branching limbs, and delicate leaves—each part playing its role to keep the whole alive...]]></description><link>https://vidushisingla.xyz/today-we-draw-a-tree-one-component-at-a-time</link><guid isPermaLink="true">https://vidushisingla.xyz/today-we-draw-a-tree-one-component-at-a-time</guid><category><![CDATA[React]]></category><category><![CDATA[State Management ]]></category><category><![CDATA[Props in reactjs]]></category><category><![CDATA[props]]></category><category><![CDATA[Frontend Development]]></category><category><![CDATA[virtual dom]]></category><category><![CDATA[components in react]]></category><category><![CDATA[components]]></category><category><![CDATA[React Component Rendering]]></category><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Wed, 03 Sep 2025 08:54:09 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756882527875/878cfcfa-451b-4a77-974c-122a9a30f09b.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Nature is full of lessons if we take a moment to observe. A tree, for example, grows gracefully from a single seed into a complex system of roots, a sturdy trunk, branching limbs, and delicate leaves—each part playing its role to keep the whole alive and thriving. Just like nature builds complexity from simple, connected pieces, React helps us build dynamic applications by breaking them into small, reusable components.</p>
<p>Before we dive into code, grab a <strong>paper and pencil</strong>, and maybe some colors. Today, we’re going to draw a tree—but not just any tree. This will be our bridge to learning React concepts like <strong>components, state, and props</strong>.</p>
<p>First, let’s list the elements we’ll need to draw our tree:</p>
<ul>
<li><p><strong>Trunk</strong></p>
</li>
<li><p><strong>Upper base</strong> – the main body of the tree connecting the trunk to the branches.</p>
</li>
<li><p><strong>Branches</strong></p>
</li>
<li><p><strong>Leaves</strong></p>
</li>
<li><p><strong>Fruits</strong></p>
</li>
</ul>
<p>Let’s quickly sketch these elements so we can see how they fit together, almost like designing a blueprint. In our tree:</p>
<p>The <strong>Trunk</strong> is the <strong>base component</strong>, holding everything together. The <strong>Upper Base</strong> sits on top of the trunk as a <strong>container component</strong>, organizing the parts inside it. <strong>Branches, Leaves, and Fruits</strong> are <strong>child components</strong>, nested inside the upper base. Each has its own role but comes together to form the complete tree.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756883876319/10dbc062-8d53-43fc-833a-f391754e6536.png" alt class="image--center mx-auto" /></p>
<p>While drawing the leaves, fruits, and branches, you might start feeling a bit tired or bored because each item seems repetitive and monotonous. Imagine having to draw ten identical fruits one by one—tedious, right? In React, we don’t have to repeat ourselves like that. Instead of manually drawing each fruit, we can create <strong>one “Fruit” component</strong> and then <strong>reuse it multiple times</strong> wherever we need it inside our tree.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756883784119/cf0ece2c-f37c-4e60-b61a-941f00cb16ab.png" alt class="image--center mx-auto" /></p>
<p>It might sound impossible at first—how can a single drawing appear in multiple places? But that’s exactly what React allows through <strong>component re-rendering</strong>. Once a component is defined, React can render it as many times as needed, each time appearing in a different part of the UI. Not only does this save time, but it also makes your code cleaner and easier to maintain. If you decide to change the appearance of the fruit later, you only need to update it in one place, and React automatically updates every instance wherever it’s used.</p>
<p>In essence, React turns repetitive work into reusable building blocks, just like having a magic stamp for your fruits and leaves—draw once, reuse everywhere.</p>
<h3 id="heading-painting-the-tree-props-and-state-in-detail">Painting the Tree: Props and State in Detail</h3>
<p>Let’s return to our canvas. The trunk, branches, leaves, and fruits all form parts of the painting. Some elements, like the trunk, are static, while others, such as the number of fruits or the color of the leaves, can change over time. Maybe you want to erase a fruit and paint a flower in its place, or fix a fruit that didn’t turn out quite right by covering it with the base color. In React, this is exactly where <strong>props</strong> and <strong>state</strong> come in—they let your tree respond to changes <strong>without having to redraw everything from scratch</strong>. Let’s explore these basics and see how they bring your tree to life!</p>
<hr />
<h4 id="heading-props-the-brushes-and-instructions"><strong>Props: The Brushes and Instructions</strong></h4>
<p>Props are like the brushes, pens, or instructions you hand to each part of the painting. They tell the component <strong>how it should appear or behave</strong>, but the component itself <strong>cannot change them</strong>.</p>
<p>For example:</p>
<ul>
<li><p>You tell a fruit: “You should be red.” → The fruit will paint itself red.</p>
</li>
<li><p>You tell a leaf: “You should be green.” → The leaf will use that color.</p>
</li>
</ul>
<p>Props are <strong>read-only</strong> and <strong>configurable from outside the component</strong>. In other words, they’re passed <strong>from a parent component to its child</strong>, like giving your child a coloring book and pencils—they can color according to your instructions, but the book’s pages don’t change themselves.</p>
<p>Props are perfect when you want:</p>
<ul>
<li><p>A component to looks different in different places (e.g., red apple here, yellow apple there).</p>
</li>
<li><p>Data to flow <strong>down the component tree</strong> without the child modifying it.</p>
</li>
</ul>
<hr />
<h4 id="heading-state-the-living-paint"><strong>State: The Living Paint</strong></h4>
<p>A state is like the paint on your canvas that <strong>can change over time</strong>. Unlike props, state is <strong>mutable</strong>—components can update their own state based on actions, events, or time.</p>
<p>For example:</p>
<ul>
<li><p>Your tree starts with 3 fruits. Picking one fruit reduces the number to 2. The state allows the component to “remember” this change and update the painting automatically.</p>
</li>
<li><p>A leaf may change color in autumn. State keeps track of the current color and updates it on the canvas.</p>
</li>
</ul>
<p>State is <strong>local to the component</strong>, meaning each component manages its own dynamic data. Think of it like this: props are instructions from outside, while state is the component’s internal diary—it tracks what’s happening and can update itself whenever necessary.</p>
<hr />
<h4 id="heading-props-vs-state-side-by-side"><strong>Props vs State: Side-by-Side</strong></h4>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td>Props</td><td>State</td></tr>
</thead>
<tbody>
<tr>
<td><strong>Purpose</strong></td><td>Configure a component</td><td>Manage dynamic data inside it</td></tr>
<tr>
<td><strong>Mutability</strong></td><td>Read-only</td><td>Mutable</td></tr>
<tr>
<td><strong>Source</strong></td><td>Passed from the parent</td><td>Managed within the component</td></tr>
<tr>
<td><strong>Use case</strong></td><td>Colors, labels, size, settings</td><td>User interactions, counters, UI changes</td></tr>
<tr>
<td><strong>Analogy</strong></td><td>Brushes and instructions</td><td>The evolving paint on canvas</td></tr>
</tbody>
</table>
</div><hr />
<h4 id="heading-how-they-work-together"><strong>How They Work Together</strong></h4>
<p>Imagine a fruit on your tree:</p>
<ul>
<li><p><strong>Props</strong> tell it “you are red and small” → the fruit renders accordingly.</p>
</li>
<li><p><strong>State</strong> tracks whether it’s been picked or eaten → if someone clicks it, the fruit disappears, updating only that fruit without touching the rest of the tree.</p>
</li>
</ul>
<p>By combining <strong>props</strong> and <strong>state</strong>, React lets you:</p>
<ul>
<li><p>Reuse components everywhere (<strong>props</strong>)</p>
</li>
<li><p>Make them interactive and responsive (<strong>state</strong>)</p>
</li>
</ul>
<p>It’s like having a painting that’s not only beautiful but <strong>alive</strong>—the colors and objects can change over time, reacting to actions or events, without repainting the entire canvas from scratch.</p>
<p>Learning React can feel overwhelming at first, but breaking it down into simple concepts—like drawing a tree—makes it much more approachable. By thinking in terms of <strong>components</strong>, <strong>props</strong>, and <strong>state</strong>, you can see how complex UIs are built from small, reusable, and interactive building blocks.</p>
<p>In the next article, we’ll take the next step: <strong>we’ll actually code and draw our tree in React</strong>. You’ll see these concepts come to life as we build a tree from trunk to leaves, making it interactive and dynamic. Get ready to turn your paper sketch into a real, working React UI!</p>
]]></content:encoded></item><item><title><![CDATA[How our childhood prepared us to code in React!]]></title><description><![CDATA[Last night, just before going to bed, I decided to sit down and paint. I kept the idea simple: a quiet landscape with trees, a mountain, a river, the open sky, and a small house. The little house had a few windows, a chimney, and a sloping roof. I be...]]></description><link>https://vidushisingla.xyz/how-our-childhood-prepared-us-to-code-in-react</link><guid isPermaLink="true">https://vidushisingla.xyz/how-our-childhood-prepared-us-to-code-in-react</guid><dc:creator><![CDATA[Vidushi Singla]]></dc:creator><pubDate>Wed, 03 Sep 2025 06:23:06 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756809575148/7ade4472-0c8a-4511-bd4c-d856e84b4032.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Last night, just before going to bed, I decided to sit down and paint. I kept the idea simple: a quiet landscape with trees, a mountain, a river, the open sky, and a small house. The little house had a few windows, a chimney, and a sloping roof. I began by sketching the outlines in pencil, then chose the colors I wanted to bring it to life. Since the trees and the ground shared the same shade, I started there, reusing the same brush. Once that was done, I washed the brush and moved on to the sky and river, gradually building the base of the painting. Finally, with my unsteady pencil strokes and a touch of black and white paint, I added some shading to give the scene depth and character.</p>
<p>Over time, this has become a daily ritual for me—a form of meditation that I practice before going to sleep. It brings me peace, helps me slow down, and strengthens my mind. But in the quiet of this routine, I stumbled upon an epiphany.</p>
<h3 id="heading-painting-feels-a-lot-like-react">Painting feels a lot like React</h3>
<p>Painting, I realized, is a lot like coding in React. Each element—whether a tree, a river, or a house—represents a <strong>component</strong>, designed to be understood and reused independently. The brushes and colors are applied thoughtfully, much like styling, to create a cohesive design. Just as I washed and reused my brush across different parts of the canvas, React reuses <strong>hooks</strong> and <strong>components</strong> to keep things modular and efficient.</p>
<p>When I added shading, the scene transformed—it gained depth, mood, and realism. This felt like working with <strong>state and props</strong> in React: subtle changes that ripple through the application, giving it life.</p>
<h3 id="heading-where-the-virtual-dom-comes-in">Where the Virtual DOM comes in</h3>
<p>But the most striking parallel came when I thought about corrections. In painting, before I repaint or adjust something, I often sketch it lightly in pencil or imagine it on a rough sheet—just to see how it fits. Only once I’m confident do I commit the final strokes on canvas.</p>
<p>This is exactly how React uses the <strong>Virtual DOM (V-DOM)</strong>. Think of the V-DOM as a lightweight, in-memory copy of the actual UI. It <strong>exists in JavaScript memory</strong>, not in the browser’s real DOM, and acts as a “draft layer” of the interface. Meanwhile, the <strong>Real DOM (R-DOM)</strong> is the actual browser-rendered UI that the user sees.</p>
<p>Whenever a component’s <strong>state or props change</strong>, React <strong>first updates the Virtual DOM</strong>. This is quick because it’s just JavaScript objects being updated in memory. React then runs a <strong>diffing algorithm</strong>, comparing the <strong>new V-DOM</strong> (after the update) with the <strong>previous V-DOM</strong>. This lets React figure out exactly what has changed.</p>
<p>Once the differences are identified, React <strong>updates only those specific parts in the Real DOM</strong>. This is more efficient than re-rendering the entire UI—like a painter touching up only the leaves of a tree instead of repainting the entire canvas.</p>
<p><strong>Interaction between V-DOM and R-DOM</strong>:</p>
<ol>
<li><p><strong>V-DOM exists in memory (JS objects)</strong>.</p>
</li>
<li><p><strong>R-DOM exists in the browser (what the user sees)</strong>.</p>
</li>
<li><p>Updates first happen in the V-DOM.</p>
</li>
<li><p>React calculates the minimal set of changes (diffing).</p>
</li>
<li><p>Only those changes are applied to the R-DOM.</p>
</li>
</ol>
<p>This approach is why React apps feel fast and responsive even when UIs are complex—because updating the V-DOM is cheap, and only necessary changes touch the Real DOM.</p>
<h3 id="heading-a-colorful-world-of-analogies">A colorful world of analogies</h3>
<p>This realization made coding in React feel more colorful, creative, and almost artistic. It’s not just logic and syntax—it’s composition, reuse, and attention to detail, much like art. And perhaps, by exploring the world through such analogies, we can make technology not only easier to understand but also more joyful to practice.</p>
<hr />
<h3 id="heading-a-small-tabular-approach-for-making-our-newfound-understanding-better">A small tabular approach for making our newfound understanding better :)</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Painting Step</strong></td><td><strong>React Equivalent</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Sketching outlines of trees, a river, and a house</td><td>Defining <strong>components</strong></td></tr>
<tr>
<td>Choosing brushes &amp; colors for different areas</td><td>Applying <strong>styling (CSS)</strong></td></tr>
<tr>
<td>Reusing the same brush for tree + ground</td><td>Reusing <strong>components &amp; hooks</strong></td></tr>
<tr>
<td>Adding shading to give depth</td><td>Managing <strong>state &amp; props</strong></td></tr>
<tr>
<td>Making a rough draft before the final stroke</td><td>Updating the <strong>Virtual DOM (V-DOM)</strong></td></tr>
<tr>
<td>Comparing the draft with the current canvas</td><td><strong>Diffing algorithm</strong></td></tr>
<tr>
<td>Touching up only the leaves instead of repainting everything</td><td>Updating only changed nodes in the <strong>Real DOM (R-DOM)</strong></td></tr>
</tbody>
</table>
</div><p>This marks the beginning of our <strong>React analogy series</strong>. Today, we explored the concept of the <strong>Virtual DOM</strong> through the lens of painting, making it easier to connect abstract technical ideas with something more tangible. In the next posts, we’ll gradually move into the <strong>foundational concepts of React</strong>—from components and props to state management and beyond. Step by step, we’ll build not just applications, but also a colorful way of understanding them.</p>
]]></content:encoded></item></channel></rss>