Context has become the default answer whenever state needs to cross more than two component levels. The problem rarely shows up on day one: the app starts clean, then a few months in a UserProvider wraps the whole tree, a NotificationsProvider receives websocket events every few seconds, and suddenly large parts of the UI re-render for no visible reason. This isn't a React bug, it's a direct consequence of what Context was actually designed to do.
What Context actually does
Context is not a state manager. It's a dependency-injection mechanism built to avoid prop drilling. Its only guarantee is that a value becomes available to every descendant of a Provider without passing it down prop by prop. It has no notion of fine-grained selection: when the value passed to the Provider changes (a new reference), every component consuming that Context through useContext re-renders, whether it actually reads the changed part or not.
const AppStateContext = createContext(null);
function AppProvider({ children }) {
const [user, setUser] = useState(null);
const [notifications, setNotifications] = useState([]);
const [theme, setTheme] = useState("light");
// A single value object: updating any one of the three states
// creates a new reference and invalidates EVERY consumer.
const value = { user, setUser, notifications, setNotifications, theme, setTheme };
return (
<AppStateContext.Provider value={value}>
{children}
</AppStateContext.Provider>
);
}
A <ThemeSwitcher /> component that only reads theme will still re-render every time a websocket notification comes in, because it consumes the same Context as everything else.
Why this actually hurts performance
The re-render itself isn't necessarily expensive on its own; React is fast at reconciling a simple tree. The real cost comes from accumulation: long lists, components with unmemoized derived calculations, third-party widgets (charts, rich text editors, maps) that recompute layout on every pass. A poorly split Context acts as a broadcast mechanism for re-renders across the whole subtree, and every branch pays the price of its heaviest component.
Diagnose before fixing anything
Before changing a single line, measure. The React DevTools Profiler, with "Record why each component rendered" enabled, gives the exact cause: Context shows up explicitly as the render reason, along with which Provider triggered it. That's the only reliable way to confirm the hypothesis instead of guessing.
// A code-level sanity check: spotting unexpected renders
function NotificationBell() {
useEffect(() => {
console.count("NotificationBell render");
});
// ...
}
If NotificationBell re-renders on every keystroke in an unrelated search field elsewhere in the app, and both share the same root Provider, the diagnosis is confirmed.
Fixes that are often enough
Split Context by domain and by change frequency
The cheapest and most common fix is to never group data that changes at very different rates into a single Context. Separating UserContext (rarely changes), ThemeContext (rarely changes) and NotificationsContext (changes often) already limits the damage: only the notification consumers pay the cost of frequent updates.
const UserContext = createContext(null);
const ThemeContext = createContext(null);
const NotificationsContext = createContext(null);
function AppProviders({ children }) {
return (
<UserContext.Provider value={userValue}>
<ThemeContext.Provider value={themeValue}>
<NotificationsContext.Provider value={notifValue}>
{children}
</NotificationsContext.Provider>
</ThemeContext.Provider>
</UserContext.Provider>
);
}
Memoize the Provider value
A classic trap: recreating the value object on every render of the Provider, even when its content hasn't actually changed (for instance because a parent re-rendered for an unrelated reason). useMemo eliminates these phantom re-renders that aren't even tied to a real data change.
const value = useMemo(
() => ({ notifications, markAsRead }),
[notifications]
);
Isolate the component that consumes the Context
When only a small part of the UI actually needs the value, extracting that part into its own component limits the blast radius of the re-render. React still has to re-render the consumer itself, but it can skip re-rendering the surrounding subtree if that subtree is passed as children and memoized.
When Context stops being enough
Context becomes a bad architectural choice, not just a perf nuisance, in three specific situations:
- High-frequency updates consumed by many scattered components (live-updating prices, a collaborative cursor, network sync status). Even well split, Context forces React to visit every consumer on every update; there's no built-in partial-selection mechanism.
- Reads that happen outside the React render cycle: business logic in a service, an Axios interceptor, a global event handler that needs to read current state without being a component.
- Advanced debugging or traceability needs (time-travel, action logs, unit-testing the store independently of components).
In these cases, an external store like Zustand, Jotai or Redux Toolkit solves the problem at the root through fine-grained selection: only components reading the changed slice re-render, via a subscription mechanism built on useSyncExternalStore rather than Context propagation.
import { create } from "zustand";
const useNotificationStore = create((set) => ({
notifications: [],
push: (n) => set((s) => ({ notifications: [...s.notifications, n] })),
}));
// Only this component re-renders when `notifications` changes,
// regardless of the rest of the tree.
function NotificationBell() {
const notifications = useNotificationStore((s) => s.notifications);
return <span>{notifications.length}</span>;
}
Tradeoffs worth owning
Context is still the right tool for low-volatility, low-fanout state: theme, locale, session configuration, static feature flags. Introducing Zustand or Redux everywhere "just in case" adds a dependency, a learning curve and another black box to maintain, for zero benefit if the state in question changes twice per session. The decision should be made per state domain, not for the whole application: a single app can legitimately use Context for authentication and Zustand for the dashboard's real-time state.
When even the external store isn't the right layer
An application store solves fine-grained selection on the client, but not consistency with the server. If the state in question is really a local copy of server data (an order list, a user profile, a cart), duplicating its management in Zustand reintroduces the classic problems of stale cache and manual synchronization. In that case, the right layer is neither Context nor a generic global store, but a data-fetching library like React Query or RTK Query, which handles caching, invalidation and revalidation on the developer's behalf.
The React Compiler changes a lot, but not this
The React Compiler (stabilized with React 19) automates a good chunk of memoization work: it inserts the equivalent of useMemo and React.memo on its own around components and derived values that don't depend on changed props or state, without the developer having to hand-write those primitives. That's a genuine improvement for eliminating re-renders caused by callbacks or objects accidentally recreated on every pass.
But the compiler doesn't change anything about the structural Context problem described above. If a Provider exposes a value object that bundles several states changing at very different rates, the compiler has no way of knowing they should be split apart: it optimizes local memoization, not the propagation architecture itself. In other words, the compiler makes low-level fixes (manual memoization, a forgotten React.memo) less necessary, but it never replaces the decision to split a Context by domain or migrate to a fine-grained-selection store when high-frequency data volume actually justifies it.
// Even with the React Compiler enabled, this split is still necessary:
// the compiler won't break up an overly broad Context for you.
const NotificationsContext = createContext(null);
const UserContext = createContext(null);
Validating the decision with a simple load test
Before migrating a state domain to an external store, it's worth quantifying the gain instead of trusting a gut feeling. The React DevTools Profiler can export commit duration per interaction; comparing that duration before and after splitting a Context (without even introducing a new dependency) often captures most of the expected gain, and helps decide whether migrating to Zustand is actually necessary or whether splitting alone is enough.
// A simple manual measurement around a critical interaction
function handleLike() {
performance.mark("like-start");
setLikes((l) => l + 1);
requestAnimationFrame(() => {
performance.mark("like-end");
performance.measure("like-duration", "like-start", "like-end");
});
}
That measurement, visible in the browser DevTools' Performance tab, objectively confirms whether the fix reduced render time, instead of relying on a vague impression of smoothness.
Takeaway: Context is built for dependency injection, not high-frequency state. Profile first to confirm the re-render actually comes from Context, split and memoize before reaching for a new dependency, and only migrate to an external store for the state domains that genuinely need it.
