Skip to content

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:

  1. Diff the new tree against the old tree
  2. Assume elements of the same type at the same position are the same (so use stable keys!)
  3. Recursively compare children
  4. Generate a list of DOM mutations
  5. 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

jsx
// 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

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary