Course contentsShow
← React
Lesson 810 of 2,39621. Context FundamentalsFree lesson

Context for Truly Global State

Identify state that genuinely needs to be accessible across your entire component tree.

Context for Truly Global State

What you'll learn: You'll discover how to identify which state genuinely belongs in Context versus what should stay local or passed as props.

Understanding "Truly Global"

Not all state deserves to live in Context. Truly global state is data that a large portion of your component tree needs to access, regardless of where those components sit in the hierarchy. Think of it as the difference between a household bulletin board (everyone needs to see it) versus a note you pass to one person (props work fine).

What Qualifies as Truly Global?

State belongs in Context when:

  • Authentication status: Nearly every component might need to know if a user is logged in
  • Theme preferences: Dark mode affects styling across your entire app
  • Language/locale: Internationalization touches text everywhere
  • Current user profile: User data often appears in headers, sidebars, and main content simultaneously

What Doesn't Qualify

State should not use Context when:

  • Only 2-3 components need it (pass props instead)
  • It's confined to one section of your app (keep it local)
  • It changes rapidly (Context updates re-render all consumers)
  • It's temporary UI state like form input or modal visibility

The Mental Test

Ask yourself: "If I changed this value, would it surprise me if half my app didn't update?" If yes, it's truly global. If only a small subtree cares, it's not.

Key Takeaway: Context is for state that crosses major application boundaries—authentication, theming, and localization are classic examples. Everything else should start local and only graduate to Context when prop drilling becomes genuinely painful across many component layers.