React.memo referential stability

The Symptom

You wrapped an expensive child in React.memo. The parent still re-renders on every keystroke, and so does the child. You double-check the import, the spelling, the wrapper — everything looks right. So why is the memo doing nothing?

The Rule React.memo Actually Enforces

React.memo does a shallow === comparison of every prop between the previous and next render. If even ONE prop is a new reference, the memo is busted and the child re-renders — no matter how “expensive” it is.

The trap: function props, object props, and array props are almost always brand-new references on every parent render unless you stabilize them. Wrapping a component in React.memo alone does not make those references stable.

The Gotcha (inline props)

function Parent() {
  const [count, setCount] = useState(0);
  return (
    <div>
      <button onClick={() => setCount(count + 1)}>inc</button>
      {/* onSelect is a NEW function every render, config a NEW object */}
      <ExpensiveChild onSelect={() => doThing()} config={{ theme: 'dark' }} />
    </div>
  );
}

const ExpensiveChild = React.memo(function ExpensiveChild({ onSelect, config }) {
  // Still re-renders on every Parent render — memo is busted!
  return <button onClick={onSelect}>{config.theme}</button>;
});

onSelect and config are recreated on every Parent render, so React.memo sees different references and re-renders the child anyway. The React.memo wrapper is pure theater here.

The Fix: stabilize with useCallback / useMemo

function Parent() {
  const [count, setCount] = useState(0);

  // Same reference across renders (until deps change)
  const handleSelect = useCallback(() => doThing(), []);
  const config = useMemo(() => ({ theme: 'dark' }), []);

  return (
    <div>
      <button onClick={() => setCount(count + 1)}>inc</button>
      <ExpensiveChild onSelect={handleSelect} config={config} />
    </div>
  );
}

Now onSelect and config keep a stable reference, so when count changes React.memo short-circuits the child’s re-render. That is the moment the memo finally earns its keep.

The Primitive Catch

Primitive props (string, number, boolean) are compared by value, so React.memo works on them automatically — no useCallback needed:

<ExpensiveChild label={title} count={count} />  // memo works for these out of the box

When This Does NOT Matter (don’t over-optimize)

  • A child that is cheap to render — memoization adds bookkeeping cost for zero gain.
  • A parent that never re-renders anyway.
  • useCallback / useMemo are not free either. Reach for them only when profiling shows a real re-render problem, or when passing props down to already-memoized children.

The Mental Model

React.memo ≠ “don’t re-render this component.”

React.memo = “don’t re-render this component unless a prop’s reference changed.”

Stabilize every prop that is a function, object, or array with useCallback / useMemo, and the memo finally does its job. Forget one, and the whole optimization silently collapses.