React Context
A React feature that lets a parent component make a value available to every component below it without passing it as props.
In more detail
createContext makes a context object, a Provider element supplies the value, and useContext reads it. Compound components use a private context to share state, such as which tab is active. Context still works inside portals because it follows the React tree, not the DOM tree.
Related terms
- compound component — A set of components designed to be used together, such as Tabs, Tabs.Trigger and Tabs.Panel, that share state behind the scenes.
- prop drilling — Passing a value through several layers of components that do not use it, just so a deeply nested one can.
- React hook — A function whose name starts with use, such as useState or useEffect, that lets a React component keep state or run side work.
- context provider — The component that supplies a context value to everything inside it.
- useContext — The React hook that reads the value of a context from the nearest provider above the component.
- createContext — The React function that creates a context object, taking the default value consumers get when no provider is above them.
- context splitting — Dividing one large context into several smaller ones so components re-render only when the data they actually read changes.
Taught in
- Headless Architecture: State vs Presentation Separation — Design Systems & Component Engineering
- Compound Component Patterns: Context Sharing & Internal State — Design Systems & Component Engineering
- Overlay Architecture: Portals, Stacking Contexts & Backdrops — Design Systems & Component Engineering
- Component Purity: Pure Functions, Idempotence And Side Effects — React 19 & Modern Component Architecture
- Props Contract: Immutability, Children, And Polymorphic Tags — React 19 & Modern Component Architecture
- Complex State with useReducer: State Machines And Action Types — React 19 & Modern Component Architecture
- useImperativeHandle: Controlled Ref Forwarding Boundaries — 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
- useOptimistic: Instantaneous UI Updates with Rollback — React 19 & Modern Component Architecture
- The use() Hook: Reading Promises And Context Directly — React 19 & Modern Component Architecture
- Error Boundaries: componentDidCatch And Fallback UI Trees — React 19 & Modern Component Architecture
- React Portals: Escaping Stacking Contexts for Modals — React 19 & Modern Component Architecture