Course contentsShow
← React
Lesson 838 of 2,39622. Context PerformanceFree lesson

The Single Context Anti-Pattern

Why putting all app state in one context causes every consumer to re-render on any state change.

The Single Context Anti-Pattern

You'll learn why cramming all your app's state into one giant context creates a performance nightmare.

The Problem with One Big Context

Imagine putting your entire app's state—user info, theme, shopping cart, notifications, UI flags, everything—into a single context. It sounds convenient: one provider, one source of truth, easy to access anywhere.

But here's the trap: every component that consumes this context will re-render whenever ANY part of that state changes.

Changed the theme from light to dark? Every component re-renders, even the shopping cart that doesn't care about themes. Updated a single notification count? Your entire user profile form re-renders too. Context doesn't have built-in subscriptions to specific pieces of state—it's all or nothing.

Why This Happens

When you call useContext(BigAppContext), React subscribes that component to the entire context value. If the provider's value prop gets a new reference (which happens on any state update), React notifies every subscribed component.

You can't pick and choose. There's no useContext(BigAppContext, 'theme') syntax. Reading any part means subscribing to all parts.

The Analogy

It's like subscribing to every news alert from every department in a company when you only care about engineering updates. Every sales announcement, HR memo, and marketing campaign triggers your notifications, drowning out what matters to you.

The Solution Preview

The fix is splitting contexts by domain or update frequency, which we'll cover next. But first, recognize the anti-pattern: one context for everything is a recipe for unnecessary re-renders across your entire component tree.

Key Takeaway: Putting all app state in one context forces every consumer to re-render on every state change, making it a performance anti-pattern for anything beyond trivial apps.