Overview
On each state change React re-renders to a new virtual tree, diffs it against the previous one (reconciliation), and applies only the changed nodes to the real DOM. This explains why stable key props and fewer needless re-renders matter. Diffing is cheap but not free: the cost is two passes in JavaScript instead of one direct mutation.
Rules
- The diff assumes elements of different types produce different trees and matches list children by
key. Use stable IDs, not array indexes, for lists that reorder. - Use refs for imperative DOM access; do not mutate nodes React manages.
- Concurrent rendering (React 18 and later) can interrupt reconciliation for higher-priority updates.
- Not every framework diffs a virtual tree: Svelte compiles to direct DOM updates and Solid uses fine-grained reactivity.
Related
- hydration: reconciles server HTML with the client tree.
- server-component: server-only output with no client diff of its own code.
- suspense-boundary: pauses rendering for async data.
- react: rendering and reconciliation.
- react-performance: re-render control.
- react-compiler: automatic memoization.