The Real DOM is the actual structure of elements in your browser (the webpage).

Updating the Real DOM directly is slow because every small change (like changing text or color) can trigger a re-render of the entire page or parts of it.

To fix this, React uses the Virtual DOM :

How does it work?

  1. Render Phase: You write a React component (JSX) -> React creates a Virtual DOM tree (a JavaScript object that represents UI structure).

  2. Update Phase: When state or props change, React creates a new Virtual DOM .

  3. Diffing Algorithm: React compares the new VDOM to the previous one to find minimal changes (called reconciliation ).

  4. Commit Phase: React updates only those changed elements in the Real DOM .

Example

function App() {
  const [count, setCount] = React.useState(0);

  return (
    <div>
      <h1>{count}</h1>
      <button onClick={() => setCount(count + 1)}>Increment</button>
    </div>
  );
}

When you click the button:

Rikam Palkar React VDOM

Benefit