Course contentsShow
← React
Lesson 941 of 2,39624. React.memoFree lesson

The Referential Stability Problem with Callbacks

Why passing inline callbacks to memoized components defeats memo's purpose and causes re-renders anyway.

The Referential Stability Problem with Callbacks

What you'll learn: Why passing inline callbacks to memoized components defeats the purpose of React.memo and causes re-renders anyway.

You've wrapped your component in React.memo to skip unnecessary re-renders. You've verified that your props are stable. But then you pass a callback function, and suddenly memo stops working. What happened?

The Inline Function Trap

Every time your parent component renders, inline functions are recreated with a new reference. Even if the function does the exact same thing, JavaScript sees it as a different function object.

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

  return (
    <ExpensiveChild 
      onClick={() => console.log('clicked')} 
    />
  );
}

const ExpensiveChild = React.memo(function ExpensiveChild({ onClick }) {
  // This still re-renders every time ParentComponent renders!
  return <button onClick={onClick}>Click me</button>;
});

Why memo Fails Here

React.memo performs shallow comparison on props. It checks if onClick has changed using Object.is(oldOnClick, newOnClick). Since the inline arrow function is recreated on every parent render, the reference changes, the comparison fails, and ExpensiveChild re-renders despite being memoized.

Think of it like this: You're giving your child a "new" instruction note every time, even though the words on it are identical. The child sees a different piece of paper and thinks something changed.

The Solution Preview

This is where useCallback becomes essential—it stabilizes the function reference across renders, making memo effective again. Without stable callback references, memoization is defeated.

Key Takeaway: Passing inline callbacks to React.memo components creates new function references every render, causing memo's shallow comparison to fail and triggering unnecessary re-renders. Stable callback references are required for memo to work.