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

Reading Context Creates a Subscription

Understanding that useContext hooks subscribe the component to all value changes from that context.

Reading Context Creates a Subscription

What you'll learn: Why calling useContext automatically subscribes your component to every change in that context's value.

When you call useContext inside a component, you're not just reading a value once—you're creating a subscription. React now watches that context for changes, and whenever the provider's value updates, your component will re-render automatically.

This subscription happens invisibly. There's no unsubscribe function to call, no explicit listener setup. The moment useContext executes, React wires up your component to receive updates.

What This Means in Practice

Think of context like a radio station broadcast. When you use useContext, you're tuning your component's radio to that frequency. As long as your component is mounted, it stays tuned in. Every new broadcast (value change) comes through immediately, triggering a re-render.

This subscription is all-or-nothing. You can't tell React "only re-render me when user.name changes, not user.age." If the context value object changes at all, every subscribed component re-renders.

The Invisible Contract

// This single line creates the subscription:
const theme = useContext(ThemeContext);

// React now automatically:
// 1. Watches ThemeContext's provider value
// 2. Re-renders this component on ANY value change
// 3. Maintains the subscription until unmount

You don't see subscription management code because React handles it behind the scenes. This is convenient but can cause performance issues if your context updates frequently and many components subscribe.

Key Takeaway: Calling useContext creates an automatic, ongoing subscription to all changes in that context—your component will re-render whenever the provider's value changes, no exceptions.