<?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[Tbel's blog]]></title><description><![CDATA[Tbel's blog]]></description><link>https://tbelblogs.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 00:47:25 GMT</lastBuildDate><atom:link href="https://tbelblogs.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Virtual DOM : React under the Hood]]></title><description><![CDATA[Coming across react , the most popular javascript framework Ofcourse! , One of the key features behind this game changer framework is the 'Virtual Dom' concept👀👀For the one's who don't know about what actually a virtual dom is, lets just understand...]]></description><link>https://tbelblogs.hashnode.dev/virtual-dom-react-under-the-hood</link><guid isPermaLink="true">https://tbelblogs.hashnode.dev/virtual-dom-react-under-the-hood</guid><dc:creator><![CDATA[Thanisha_Belchada]]></dc:creator><pubDate>Tue, 16 Jan 2024 05:12:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1705378939595/2b827ae6-49e9-4a58-9950-78bb0a8c6b35.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Coming across react , the most popular javascript framework Ofcourse! , One of the key features behind this game changer framework is the 'Virtual Dom' concept👀👀<br />For the one's who don't know about what actually a virtual dom is, lets just understand it quickly.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">The virtual DOM is like a blueprint that helps a websites update efficiently by comparing changes to the actual DOM i.e react DOM before applying them to the actual web page.</div>
</div>

<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1705378617415/d85d3102-d8b7-4bf9-ac12-fe7b86ecc645.png" alt class="image--center mx-auto" /></p>
<hr />
<h2 id="heading-how-does-it-work">How Does It Work?</h2>
<p>The virtual DOM works by syncing with the real DOM and the process of reconciliation,Now what's reconciliation? When a change is made to the UI, React updates the virtual DOM, which is a tree-like structure of JavaScript objects. React then compares the new virtual DOM with the previous version to determine what has changed. This process is called reconciliation.</p>
<p>Reconciliation is an efficient way to update the UI because React only updates the parts of the DOM that have changed. This is in contrast to traditional DOM manipulation, where developers have to manually update the entire DOM tree, even if only a small part of it has changed.</p>
<hr />
<h2 id="heading-benefits-of-virtual-dom">Benefits of Virtual DOM</h2>
<p>The virtual DOM provides several benefits, including better performance and efficient updates. Because React only updates the parts of the DOM that have changed, it's faster and more efficient than traditional DOM manipulation. Additionally, the virtual DOM makes it easier to reason about the state of the UI, which can lead to fewer bugs and more maintainable code.</p>
<p><strong>Checkout the below code to understand the use of Virtual DOM in React :</strong></p>
<pre><code class="lang-typescript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Counter</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>);

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handleClick</span>(<span class="hljs-params"></span>) </span>{
    setCount(count + <span class="hljs-number">1</span>);
  }
  <span class="hljs-keyword">return</span> (
    &lt;div&gt;
      &lt;p&gt;You clicked {count} times&lt;/p&gt;
      &lt;button onClick={handleClick}&gt;Click me&lt;/button&gt;
    &lt;/div&gt;
  );
}
</code></pre>
<p>In the above code, we're using React's useState hook to manage the state of a counter. When the user clicks the button, the handleClick function updates the state, which triggers a re-render of the component. React then updates the virtual DOM and reconciles it with the previous version to determine what has changed. Finally, React updates the actual DOM with only the necessary changes.</p>
<blockquote>
<p>The virtual DOM is not faster than the actual DOM. It's just a more efficient way to update the UI.</p>
<p>React's virtual DOM implementation uses internal objects called "fibers" to manage the reconciliation process.</p>
<p>The virtual DOM is not unique to React. Other libraries and frameworks, such as Vue.js and Angular, also use a virtual DOM.</p>
</blockquote>
<h3 id="heading-conclusion">Conclusion:</h3>
<p>The virtual DOM is a key feature of React that provides a mechanism to abstract manual DOM manipulations away from developers, making code more predictable and efficient. By understanding the virtual DOM, developers can write more maintainable and performant code.</p>
]]></content:encoded></item></channel></rss>