Context Updates: memo Doesn't Stop Those
What you'll learn: Why wrapping a component in React.memo won't prevent re-renders triggered by context value changes.
The Surprising Limitation
You've learned that React.memo helps components skip re-renders when their props haven't changed and the parent re-renders. But here's a critical limitation: memo only checks props—it has no effect on context subscriptions.
When a component uses useContext to read from a Context Provider, it subscribes directly to that context. Whenever the context value changes, every component subscribed to that context will re-render, regardless of whether it's wrapped in React.memo or not.
The Mental Model
Think of context like a broadcast system. When you call useContext, you're tuning into a radio station. React.memo is like a filter on your component's door that checks visitors (props) before letting them in. But the radio signal (context updates) bypasses the door entirely—it comes through the walls. Your component hears the broadcast no matter what security you put on the door.
Why This Happens
Context updates trigger re-renders through a completely separate mechanism than props. The memo wrapper only intercepts prop changes from the parent component. It doesn't—and can't—intercept context value changes because those don't flow through props.
This is why the "Context Value Stability" lessons you learned earlier are so important. You can't rely on memo to protect components from context-driven re-renders. You need stable context values, split contexts, or selective subscription patterns.
When This Bites You
You wrap an expensive component in React.memo, test it, and performance still suffers. You check—props are stable. What's wrong? The component uses context, and that context value is changing frequently.
Key Takeaway: React.memo only prevents re-renders from prop changes—it cannot stop re-renders caused by context updates. Context subscriptions bypass memo entirely.