useContext
The React hook that reads the value of a context from the nearest provider above the component.
In more detail
The component subscribes to that context and re-renders whenever the provider value changes, even if it uses only part of it. Unlike use, useContext must follow the rules of hooks and cannot be called inside a condition.
Examples
Tabs triggers call useContext(Ctx) to learn which tab is active; a custom hook wrapping it should throw if no provider is found.const { mode } = useContext(ThemeContext);Related terms
- React Context — A React feature that lets a parent component make a value available to every component below it without passing it as props.
- context provider — The component that supplies a context value to everything inside it.
- use() — The React 19 API that reads a value from a Promise or a context, and unlike hooks may be called inside conditions and loops.
Taught in
- Compound Component Patterns: Context Sharing & Internal State — Design Systems & Component Engineering
- Lifting State Up: Colocation, Ownership, And Data Flow — React 19 & Modern Component Architecture
- useContext in Depth: Scoping, Consumer Subscription Costs — React 19 & Modern Component Architecture
- Compound Components: Inversion of Control with Context — React 19 & Modern Component Architecture