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

The Selective Subscription Problem

Why consuming only part of context still triggers re-renders on any context change, and when this becomes a bottleneck.

The Selective Subscription Problem

You'll learn why reading just one field from context still makes your component re-render whenever any field changes.

The Core Issue

When you call useContext, React subscribes your component to the entire context value—not just the specific properties you read from it. Even if you only use context.userName, your component will re-render when context.theme changes, or context.settings updates, or any other field in that context object changes.

This is selective subscription: wanting to subscribe to only part of the context. Unfortunately, React doesn't support it natively.

Why This Happens

Think of context like subscribing to a newspaper. You might only read the sports section, but you still get the entire newspaper delivered every day. When any section changes—even the classifieds—a new edition arrives at your door, and you have to at least acknowledge it arrived.

Similarly, useContext doesn't let you say "only re-render me when user.name changes." It's all-or-nothing: any change to the context value triggers re-renders in all consumers.

When This Becomes a Bottleneck

If your context contains multiple unrelated pieces of state (user info, theme, notifications, settings), and components only care about one piece, you'll see unnecessary re-renders. A component reading only theme will re-render when user info changes. Multiply this across dozens of components, and performance suffers—especially if those components have expensive render logic.

Key Takeaway: useContext subscribes you to the entire context value; using only one field doesn't prevent re-renders when other fields change, making large multi-purpose contexts a performance liability.