0
Challenge · 90React Internals
Reconciliation
Internalsused in ~50% of apps
Why does typing in an input sometimes survive a re-render and sometimes vanish? Why does swapping a div for a section silently reset a component's state? The answer is reconciliation — React's algorithm for deciding what to keep, update, or throw away.
Core idea. On every render React produces a new tree of elements and diffs it against the previous one, position by position: same element type at the same spot means keep the instance and patch the changes; a different type means tear the old subtree down and build a fresh one. Keys override position so children keep their identity across reorders.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
OLD TREE (last render)DIFFNEW TREE (this render)
<div>
<div>
<h1>"Hello"</h1>
<h1>"Welcome"</h1>
<Counter/>3
<Counter/>3
React walks the OLD and NEW trees together, one position at a time. Press Step diff to compare the next node.
0/3 nodes compared
state before state kept state reset to 0
↑ play a little first, then dig in