Summary
Immutable updates reuse unchanged subtrees — only changed paths get new references. Enables cheap equality checks and memoization (Immer, Redux Toolkit). Shallow copy of top level without sharing deep nodes breaks memo benefits. Structural sharing is why === on root state can still mean "nothing changed" for subtrees.
Code example
function updateUser(state, patch) {
return {
...state,
profile: { ...state.profile, ...patch },
};
}
// Unchanged profile.avatar reference is reused (structural sharing)
Key points
- Immutable updates reuse unchanged subtrees — only changed paths get new references.
- Enables cheap equality checks and memoization (Immer, Redux Toolkit).
- Shallow copy of top level without sharing deep nodes breaks memo benefits.
- Structural sharing is why
===on root state can still mean "nothing changed" for subtrees.