<?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[Harshil Prajapati]]></title><description><![CDATA[Explore tech, coding, online income ideas, and smart investing tips. Learn web & mobile development and grow your digital skills.]]></description><link>https://blog.harshilprajapati.com</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1766941801065/b559278b-0438-4b79-9c68-fcbd5ac49d77.png</url><title>Harshil Prajapati</title><link>https://blog.harshilprajapati.com</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 13 May 2026 18:41:57 GMT</lastBuildDate><atom:link href="https://blog.harshilprajapati.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How React Virtual DOM Works Under the Hood]]></title><description><![CDATA[Modern web apps feel fast and responsive—but have you ever wondered how React makes UI updates so efficient?
The answer lies in one of React’s core ideas: Virtual DOM.
Let’s break it down step by step]]></description><link>https://blog.harshilprajapati.com/how-react-virtual-dom-works-under-the-hood</link><guid isPermaLink="true">https://blog.harshilprajapati.com/how-react-virtual-dom-works-under-the-hood</guid><category><![CDATA[react js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[DOM]]></category><category><![CDATA[ChaiCode]]></category><dc:creator><![CDATA[Harshil Prajapati]]></dc:creator><pubDate>Mon, 04 May 2026 13:14:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6951083ca4fb820805e2ca1a/35a32532-aca3-4057-b1ab-ad1812b1ba6d.webp" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Modern web apps feel fast and responsive—but have you ever wondered <em>how React makes UI updates so efficient</em>?</p>
<p>The answer lies in one of React’s core ideas: <strong>Virtual DOM</strong>.</p>
<p>Let’s break it down step by step in a simple, practical way.</p>
<hr />
<h3>The Problem: Slow DOM Updates</h3>
<p>The <strong>Real DOM</strong> (the actual browser DOM) is powerful—but it’s also <strong>slow to update</strong>.</p>
<p>Every time you :</p>
<ul>
<li><p>Change content</p>
</li>
<li><p>Update styles</p>
</li>
<li><p>Add/remove elements</p>
</li>
</ul>
<p>…the browser has to :</p>
<ol>
<li><p>Recalculate styles</p>
</li>
<li><p>Reflow layout</p>
</li>
<li><p>Repaint the screen</p>
</li>
</ol>
<p>Doing this frequently can <strong>hurt performance</strong>, especially in large applications.</p>
<hr />
<h2>Real DOM vs Virtual DOM</h2>
<h3>Real DOM</h3>
<ul>
<li><p>Actual UI rendered in the browser</p>
</li>
<li><p>Heavy and slow to update</p>
</li>
<li><p>Every change triggers re-rendering work</p>
</li>
</ul>
<h3>Virtual DOM</h3>
<ul>
<li><p>Lightweight JavaScript object (a copy of the Real DOM)</p>
</li>
<li><p>Stored in memory</p>
</li>
<li><p>Fast to create and update</p>
</li>
</ul>
<p>Think of Virtual DOM as a <strong>blueprint of your UI</strong>, not the UI itself.</p>
<hr />
<h2>Initial Render in React</h2>
<h3>Real DOM</h3>
<ul>
<li><p>Actual UI rendered in the browser</p>
</li>
<li><p>Heavy and slow to update</p>
</li>
<li><p>Every change triggers re-rendering work</p>
</li>
</ul>
<h3>Virtual DOM</h3>
<ul>
<li><p>Lightweight JavaScript object (a copy of the Real DOM)</p>
</li>
<li><p>Stored in memory</p>
</li>
<li><p>Fast to create and update</p>
</li>
</ul>
<hr />
<h2>What Happens When State or Props Change?</h2>
<h3>Whenever :</h3>
<ul>
<li><p><code>state</code> updates</p>
</li>
<li><p><code>props</code> change</p>
</li>
</ul>
<p>React does <strong>NOT</strong> directly update the Real DOM.</p>
<p>Instead, it follows a smart process :</p>
<ol>
<li><p>Create a New Virtual DOM Tree</p>
</li>
<li><p>Diffing (Reconciliation)</p>
</li>
<li><p>Find Minimal Changes</p>
</li>
<li><p>Update the Real DOM</p>
</li>
</ol>
<hr />
<h2>Why This Improves Performance</h2>
<p>Instead of :</p>
<ul>
<li>Updating entire DOM repeatedly</li>
</ul>
<p>React does :</p>
<ul>
<li><p>Update only necessary parts (efficient)</p>
</li>
<li><p>Compare in memory (fast)</p>
</li>
</ul>
<p>Result :</p>
<ul>
<li><p>Faster UI updates</p>
</li>
<li><p>Better performance</p>
</li>
<li><p>Smoother user experience</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>