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

Taught in

References