How Context Triggers Re-renders
What you'll learn: You'll understand that when a Context Provider's value changes, every component consuming that context will re-render—even if they only use a small part of it.
The All-or-Nothing Re-render Mechanism
When you update a Context Provider's value prop, React treats it as a broadcast signal. Every component that calls useContext for that specific context will re-render, regardless of which part of the context value they actually read.
Think of Context like a fire alarm in a building. When it goes off, everyone evacuates—not just the people near the fire. Similarly, when the context value changes, all consumers re-render, even if only one property in the context object changed and they don't use that property.
Why This Matters
// If this value changes...
<ThemeContext.Provider value={{ color, fontSize, spacing }}>
{/* ALL these components re-render */}
<Header /> {/* uses only color */}
<Sidebar /> {/* uses only fontSize */}
<Footer /> {/* uses only spacing */}
</ThemeContext.Provider>
Even though Header only reads color, it will re-render when fontSize or spacing change. React doesn't track which properties you access inside the context value—it only knows the entire value object changed.
The Identity Check
React uses referential equality (===) to detect context changes. If you pass a new object to value, even with identical contents, all consumers re-render. This is why you'll learn optimization techniques in upcoming lessons.
Key Takeaway: Context value changes trigger re-renders in all consuming components, not just those affected by the specific data that changed—React doesn't granularly track context property access.