Virtual DOM Playground

Try it

Click once, watch what React touches

Counter owns the state and one local variable. React rebuilds a virtual tree in memory, compares it with the previous one, and writes only the difference to the real DOM.

  1. 1

    Edit the variable

    Press shopName += "!" a few times. Nothing is called and the screen never changes.

  2. 2

    Trigger a render

    Press setCount. Counter runs again and the variable starts over.

  3. 3

    Follow the tree

    Watch the virtual DOM rebuild, produce a patch list, and hand it to the real DOM.

  4. 4

    Slow it down

    Switch to Step by step and press Next to move through each stage.

Press setCount. The cycle plays by itself, one stage at a time.

Components React calls

your functions, run during render

<App />
<Header />
<Counter />
kept by Reactcount = 0
new every callshopName = “Corner Shop”
<ShopName />
text = “Corner Shop”
<Label />
returns “Count: 0”
<Button />
onClick → setCount

Virtual DOM React builds

plain objects in memory, never painted

children: “Welcome”
children: “Corner Shop”
children: “Count: 0”
children: “+1”

Patch list (diff result)

  • empty

Real DOM React writes

the browser’s tree, painted on screen

“Welcome”
“Corner Shop”
“Count: 0”
“+1”
“© 2026”
document.titleCount: 0
–of 7 components called
–of 7 virtual nodes rebuilt
–real DOM node changed

Counter() calls

    Building and comparing plain objects is cheap, and it lets React write only what differs to the real DOM. Header and Footer keep their old elements because App did not run again. ShopName, Label and Button run again because their parent did, and React.memo could skip them.