Category: react
what is virtual dom
Published on 22 May 2026
Explanation
Virtual DOM is a lightweight copy
of the real DOM used by
React to improve performance.
Code:
const virtualDOM = { type: 'h1', props: {
children: 'Hello' } };
Explanation
Instead of updating the real DOM
directly, React first updates the Virtual
DOM and compares the changes.
Code:
Old Virtual DOM -> New Virtual DOM -> Compare Changes
Explanation
The comparison process is called Diffing.
React finds only the changed elements.
Code:
if(oldText !== newText) { updateDOM(); }
Explanation
After finding differences, React updates
only
the required parts in the real
DOM. This process is called Reconciliation.
Code:
React updates only modified nodes instead of reloading the full page.
Explanation
Using Virtual DOM improves application
performance
because direct DOM manipulation is slow.
Code:
Virtual DOM -> Faster UI Updates
Explanation
Example: If only one button text
changes, React updates only that button
instead of the complete webpage.
Code:
Before: <button>Save</button> After: <button>Saved</button>