The Reconciliation Diffing Algorithm
Understand the specific heuristics React's diffing algorithm uses to efficiently compare two element trees.
React's reconciliation algorithm is a heuristic, not a theoretically optimal tree-diff (a fully general tree-diff algorithm is O(n³), too slow for UI updates), built on two practical assumptions that hold true for the vast majority of real UI trees: elements of different types produce substantially different trees (so React doesn't try to diff their children at all, it tears down the old subtree and builds a new one), and keyed children provide identity across renders, letting React match and reorder items instead of rebuilding them.
React's diffing heuristic is like a moving crew that, when told 'the item at this spot in the truck used to be a couch and is now a bookshelf,' doesn't try to salvage any couch parts for the bookshelf — they just remove the couch entirely and bring in a fresh bookshelf; but if told 'it's still a couch, just reupholstered,' they keep the same couch frame in place and only swap the fabric.