Skip to main content

Context visual mental model

Context solves distribution through a subtree. It does not create ownership by itself.

Ownership vs distribution
State owner

useState, useReducer, external store, or another authoritative source owns the value.

Context Provider

makes the current value available below this point in the tree

Consumer A
Consumer B
Nested feature

Closest-provider mental model​

Context follows the rendered tree
ThemeContext = light
Header

reads light

Nested ThemeContext = dark
Editor

reads dark

Provider placement defines scope​

Put providers around the smallest correct ownership boundary
Too low

Some consumers cannot reach the value.

Correct scope

All intended consumers are covered without making the value app-global.

Too high

Unrelated features become coupled to the same provider and update scope.

Context update propagation​

A changed provider value notifies consumers
Owner produces next value
Provider value changes
Consumer A
Consumer B
Consumer C

Context itself does not provide selector-style subscriptions to only one field of an object. Split contexts or choose an external store when update frequency and subscription granularity demand it.

Should this value use Context?
One component or nearby siblings?Prefer local/lifted state first
Stable environment value across a subtree?Context is a strong fit
Many high-frequency fields with selective subscriptions?Consider an external store
Remote cached server data?Use server-state architecture instead
Need a provider-scoped service/store instance?Context can inject that instance

Split read and write responsibilities when useful​

Read context + dispatch context
State Context

Components that render from state subscribe to state changes.

Dispatch Context

Components that only dispatch actions can depend on a stable dispatch function.

Continue with Context and useContext and Context Architecture and Performance for complete examples and provider-design guidance.