Dev.Lib
arrow_backBack to Blogs
LEVEL_044.1June 27, 20261 min read

Structural sharing

State & Data Flow

Immutable updates reuse unchanged subtrees — only changed paths get new references.

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.

Further reading

Related concepts