The Default Behavior: Why Shallow is Usually Right
You'll learn why React.memo's default shallow comparison is the right choice for most components, and why going deeper would cause more problems than it solves.
The Economics of Comparison
When React.memo compares props, it performs a shallow equality check by default—comparing each prop value with Object.is. This might seem "cheap" or incomplete at first. Why not check deeply nested objects to catch every possible difference?
The answer is simple: shallow comparison is fast, and deep comparison would be devastatingly slow.
Why Shallow is Fast
Checking if props.user === prevProps.user is a single reference comparison—lightning fast, regardless of how complex the user object is internally. React can check dozens of props in microseconds.
A deep comparison would need to recursively traverse every property in every object, every element in every array. For large data structures, this could take longer than just re-rendering the component.
Why Shallow is Correct
Here's the crucial insight: if you're following React best practices, shallow equality is semantically correct.
When you update state immutably (creating new objects instead of mutating), reference changes perfectly indicate when data has changed. If user is a new reference, something about the user changed. If it's the same reference, nothing changed.
Deep equality would actually break this contract. It might say "these objects are equal" even though you intentionally created a new reference to trigger an update.
The Analogy
Think of it like checking if someone changed their phone. Shallow equality asks: "Is this a different phone?" Deep equality would disassemble both phones to compare every circuit. The first question is faster and actually more useful.
Key Takeaway: Shallow comparison is React.memo's superpower—it's fast enough to be worth doing and accurate when you follow immutable update patterns. Deep comparison would be slow, surprising, and break React's update model.