Home
← All questions

Context API performance pitfalls in React

HardPremiumReact

Asked at Meta · Netflix · Shopify

React interview practice: Why Context causes unnecessary re-renders and how to fix it at scale.

Answer

When a Context value changes, every consumer re-renders — even if they only use an unrelated slice. This is O(consumers) per update, which hurts large apps (theme + auth + cart in one provider).

Mitigations:

  1. Split contexts by update frequency (AuthContext vs ThemeContext).
  2. Memoize the value — useMemo(() => ({ user, login }), [user, login]).
  3. Selector pattern — store state in external store (Zustand, Redux) or use use-context-selector.
  4. Component composition — pass children as prop so parent re-renders don't force remount of static subtrees.
Premium question

Unlock the full model answer with Mentoxis Premium.

Unlock with Premium