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

Interaction with useCallback/useMemo Cascade

See how one memo'd component forces useCallback/useMemo wrapping upstream, creating optimization cascades.

Interaction with useCallback/useMemo Cascade

What You'll Learn

You'll discover how wrapping one component in React.memo can trigger a chain reaction, forcing you to add useCallback and useMemo throughout your parent components.

The Cascade Effect

When you wrap a child component with React.memo, you've told React: "Only re-render this component if its props change." But here's the catch—props that are functions or objects will always appear "changed" unless you stabilize them.

This creates a domino effect:

  1. You memo a child component to prevent unnecessary re-renders
  2. Now you must wrap any function props with useCallback in the parent
  3. If those useCallback hooks depend on objects, you must wrap those with useMemo
  4. If the parent is also memo'd by its parent, the cycle continues upward

The Optimization Spiral

Think of it like building a house of cards: once you start, each card requires supporting cards beneath it. One React.memo at the bottom of your component tree can force you to add memoization hooks all the way up the chain.

// Child is memo'd
const ExpensiveChild = React.memo(({ onAction, config }) => {
  // rendering logic
});

function Parent() {
  // Now you MUST use useCallback or memo won't help
  const handleAction = useCallback(() => {
    // logic
  }, []);
  
  // And useMemo for object props
  const config = useMemo(() => ({ theme: 'dark' }), []);
  
  return <ExpensiveChild onAction={handleAction} config={config} />;
}

Without useCallback and useMemo, the memo'd child would re-render anyway because it receives "new" functions and objects every time.

Key Takeaway: React.memo doesn't work in isolation—it often requires a cascade of useCallback and useMemo wrappers up the component tree, which is why profiling before optimizing is essential to determine if the complexity is worth it.