Reconciliation Algorithm
In one line
Reconciliation compares old and new virtual DOM trees to find the minimum set of DOM mutations needed.
In simple words
Reconciliation is React's process of comparing the previous virtual DOM with the new one and determining what changed. It runs after every state/prop update.
The algorithm:
- Diff the new tree against the old tree
- Assume elements of the same type at the same position are the same (so use stable keys!)
- Recursively compare children
- Generate a list of DOM mutations
- Apply all mutations at once
Key rules: different element types → tear down and rebuild. Same type → update props. Lists need keys to preserve identity. The algorithm is O(n) because it assumes siblings rarely reorder.
Example
// Without keys — React may incorrectly reuse DOM nodes
function BadList({ items }) {
return items.map(item => <div>{item.name}</div>);
}
// With keys — React can match items across renders
function GoodList({ items }) {
return items.map(item => (
<div key={item.id}>{item.name}</div>
));
}
// Type change triggers full teardown
function Example({ isInput }) {
// Changing between <input> and <textarea>
// tears down and rebuilds — no reuse
return isInput
? <input defaultValue="hello" />
: <textarea defaultValue="hello" />;
}Keys help reconciliation match elements across renders. Type changes cause full teardown. Without keys, React may incorrectly reuse DOM nodes.
Common confusions
Confused with: virtual DOM
The difference: The virtual DOM is the in-memory tree representation. Reconciliation is the algorithm that compares two virtual DOM trees (old and new) to determine what DOM updates are needed. Virtual DOM is the data structure; reconciliation is the process.
Related terms
Related Resources
Related Lessons
- React Internals
Reconciliation.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.