memo Doesn't Stop Internal State Changes
What you'll learn: Why React.memo doesn't prevent a component from re-rendering when its own state changes.
The Core Idea
React.memo is designed to prevent unnecessary re-renders caused by parent components. It compares incoming props and decides whether to skip rendering. However, memo has absolutely no control over what happens inside the component itself. If the component has its own useState hook and that state changes, the component must re-render — memo can't and won't stop it.
Think of memo as a gatekeeper at the component's door, checking visitors (props) from the outside. But if someone inside the house rearranges furniture (changes state), the gatekeeper has no say in that.
Why This Makes Sense
State changes are intentional updates. When you call a state setter function like setCount(5), you're explicitly telling React "this component needs to update." memo only prevents re-renders that would happen for no good reason (unchanged props from a parent). It doesn't override your deliberate state updates.
The same principle applies to useContext: if your memoized component reads from a context and that context value changes, the component subscribes to that change and will re-render, regardless of memo.
What memo Actually Controls
- ✅ Re-renders triggered by parent re-renders (when props haven't changed)
- ❌ Re-renders triggered by
useStateinside the component - ❌ Re-renders triggered by
useContextinside the component
Key Takeaway: React.memo only shields components from external re-render triggers (parent updates with unchanged props). It never blocks re-renders caused by internal state or context changes — those are intentional and necessary.