createContext(defaultValue) returns a context object that holds no value of its own; it's a key that ties providers to readers. A component provides a value by rendering <ThemeContext value={theme}> (React 19; the older <ThemeContext.Provider> still works) and reads it with useContext(ThemeContext) or use(ThemeContext), which, unlike useContext, can be called inside a condition or loop.
The lookup goes up from the reading component to the nearest provider of that context:
- Nested providers override outer ones for their subtree, like CSS inheritance.
- A provider rendered by the reading component itself doesn't count; it must be above.
- The default is used only when there's no provider at all.
<ThemeContext value={undefined}>gives readersundefined, not the default.
Every component in between is unaffected: context skips the intermediate layers, which is the point, compared with drilling props.
Why every reader re-renders: when the provider renders with a new value, React compares it with the previous one using Object.is. If it changed, React schedules a render for every component below that read this context, wherever it is. That bypasses the usual reasons a subtree is skipped: a memo parent whose props didn't change, or elements passed in as children that weren't recreated. The reader re-renders as a whole, even if it uses only one field of an object value; there's no built-in way to subscribe to part of it.
Context is a channel, not state. To change what readers see, keep state in the provider's component and pass it as value. React's docs suggest passing props or JSX as children first, and context when distant parts of the tree need the same data: theme, current user, router.