← React Beginner Questions - Set 1 Q6

What is the virtual DOM in React?

React Beginner Questions - Set 1

You cannot see the virtual DOM, but you can prove it exists by watching what React actually touches when state changes.

Example

import { useState } from 'react';

export default function Ticker() {
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>Static text — never re-created in the DOM</p>
      <button onClick={() => setCount(c => c + 1)}>Count: {count}</button>
    </div>
  );
}

// In DevTools: inspect the <p>. After many clicks its DOM node
// stays identical, while the button's text node is the one updated.

What to notice

← Back to the question list