Course contentsShow
← React
Lesson 2249 of 2,39649. Performance: Identifying ProblemsFree lesson

When Context Causes Every Consumer to Re-render

Understanding why any change to context value triggers re-renders in all components using useContext, regardless of what they actually read.

When Context Causes Every Consumer to Re-render

You'll learn why any change to a context value triggers re-renders in every consuming component, even if they don't use the changed data.

The Context Re-render Problem

When you update a React Context value, every component that calls useContext for that context will re-render, regardless of what part of the context value they actually read or use. This is by design, but it can create significant performance issues.

Think of Context like a loudspeaker announcement system in a building. When the announcement changes, everyone listening hears it—even if the message is only relevant to people on the third floor. There's no way for listeners to say "only notify me about accounting updates."

Why This Happens

React doesn't track which properties of the context value each component uses. It only knows "this component subscribed to this context." When the context provider's value changes (even a single property in an object), React marks all subscribers as needing updates.

This becomes particularly problematic when you store multiple unrelated pieces of state in one context:

// Every consumer re-renders when ANYTHING changes
const AppContext = createContext();

function Provider({ children }) {
  const [user, setUser] = useState(null);
  const [theme, setTheme] = useState('light');
  const [settings, setSettings] = useState({});
  
  // New object every render!
  const value = { user, theme, settings, setUser, setTheme };
  
  return <AppContext.Provider value={value}>{children}</AppContext.Provider>;
}

Even if a component only reads theme, it re-renders when user changes. The component can't "subscribe" to just part of the context.

The Root Cause

Context was designed for infrequent updates like theme or authentication, not as a general-purpose state management solution. The all-consumers-re-render behavior is intentional simplicity, not a bug.

Key Takeaway: Any change to a context value triggers re-renders in all useContext consumers, regardless of what they read—you can't selectively subscribe to parts of the context object.