createContext
The React function that creates a context object, taking the default value consumers get when no provider is above them.
In more detail
Call it once outside components and export the result. The default is used only when no matching provider wraps the reader, which is useful for detecting components used in the wrong place.
Example
const ThemeContext = createContext({ mode: "light" });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.
- useContext — The React hook that reads the value of a context from the nearest provider above the component.
Taught in
- Compound Component Patterns: Context Sharing & Internal State — Design Systems & Component Engineering
- useContext in Depth: Scoping, Consumer Subscription Costs — React 19 & Modern Component Architecture
- Compound Components: Inversion of Control with Context — React 19 & Modern Component Architecture
- The use() Hook: Reading Promises And Context Directly — React 19 & Modern Component Architecture