React8h estimated

The Virtual DOM & Reconciliation

Difficulty
Importance

The problem

Directly rebuilding the entire real DOM from scratch on every state change would be correct but far too slow — real DOM operations are expensive, so React needs a way to figure out the minimal set of actual changes needed and apply only those.

Why now

The critical rendering path already established that DOM/layout changes are expensive; components and JSX already established that a re-render produces a whole new UI description. Reconciliation is the missing step between those two facts — a diffing algorithm that compares the new description to the old and computes the minimal real-DOM update.

Mental model

Every re-render produces a brand-new lightweight tree description (the virtual DOM); React compares it to the previous one, node by node, using the same tree-traversal ideas from graph theory and trees, and only touches the real DOM where something actually differs — which is why re-rendering a component is cheap even though it looks like 'the whole thing runs again.'

Requires

Unlocks

Used in

Projects

  • Use React DevTools' 'highlight updates' feature to visually observe which real DOM nodes actually change when state updates, versus which components merely re-render
  • Explain, using a diagram, the difference between a component re-rendering (function runs again) and the DOM actually updating (real node change)

Examples

  • Updating one item's text in a 1,000-item list re-runs the list component's render, but reconciliation only touches the one real DOM node that changed
  • Two consecutive renders producing an identical virtual DOM subtree result in zero real DOM changes for that subtree

Resources

Mastery checklist