React · Frontend system thinking

Why do all context consumers re-render when the context value changes?

HardContextre-rendersperformanceUpdated Oct 2026
Quiz this track

Short answer

Context compares the provider value with Object.is. When it changes, every consumer under that provider is scheduled to re-render, and React.memo on a consumer does not block a context update.

Context is a subscription mechanism. Each consumer subscribes to the nearest provider for that context. When the provider receives a new value that is not Object.is equal to the previous one, React marks all subscribers as needing an update. The update comes from context itself, so memoizing the consumer's props does not prevent it.

jsx
function App() {
  const [user, setUser] = useState({ name: "Asha" });

  const value = { user, setUser };

  return (
    <UserContext value={value}>
      <Header />
      <Profile />
    </UserContext>
  );
}
A new value object is created on every App render, so every consumer re-renders even when user did not change.

Ways to reduce context churn

  • Split state and actions into separate contexts
  • Memoize the provider value when its parts are stable
  • Keep the provider as close as possible to its consumers
  • Pass stable children through a memoized provider component
  • Use an external store with selectors when consumers need fine-grained subscriptions
jsx
const UserContext = createContext(null);
const UserActionsContext = createContext(null);

function UserProvider({ children }) {
  const [user, setUser] = useState(null);
  const actions = useMemo(() => ({ setUser }), []);

  return (
    <UserContext value={user}>
      <UserActionsContext value={actions}>
        {children}
      </UserActionsContext>
    </UserContext>
  );
}
Components that only dispatch actions do not re-render when the user record changes.

React 19 also allows use(Context) inside conditionals, but that changes where a context can be read, not how subscriptions behave. The value identity rule still applies.

Do not assume React.memo fixes context performance. It can reduce parent-driven renders, but a context value change still reaches every consumer.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1How does React compare context values?
  2. 2Can React.memo stop a context-driven re-render?
  3. 3Why does an inline object provider value cause extra renders?
  4. 4When is a selector-based store a better choice than Context?

Say it in the interview

Context consumers subscribe to the nearest provider. When the provider value changes by Object.is, React schedules every consumer to update, and memoizing the consumer's props does not stop that. The common mistake is creating a new object value on every provider render. I split independent contexts, memoize stable values and keep providers close to consumers. If I need fine-grained subscriptions, I use an external store with selectors.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React mock interview and get scored feedback on depth, clarity and confidence.