--- title: createContext --- `createContext` lets you create a [context](/learn/passing-data-deeply-with-context) that components can provide or read. ```js const SomeContext = createContext(defaultValue) ``` --- ## Reference {/*reference*/} ### `createContext(defaultValue)` {/*createcontext*/} Call `createContext` outside of any components to create a context. ```js import { createContext } from 'react'; const ThemeContext = createContext('light'); ``` [See more examples below.](#usage) #### Parameters {/*parameters*/} * `defaultValue`: The value that you want the context to have when there is no matching context provider in the tree above the component that reads context. If you don't have any meaningful default value, specify `null`. The default value is meant as a "last resort" fallback. It is static and never changes over time. #### Returns {/*returns*/} `createContext` returns a context object. **The context object itself does not hold any information.** It represents _which_ context other components read or provide. Typically, you will use [`SomeContext.Provider`](#provider) in components above to specify the context value, and call [`useContext(SomeContext)`](/reference/react/useContext) in components below to read it. The context object has a few properties: * `SomeContext.Provider` lets you provide the context value to components. * `SomeContext.Consumer` is an alternative and rarely used way to read the context value. --- ### `SomeContext.Provider` {/*provider*/} Wrap your components into a context provider to specify the value of this context for all components inside: ```js function App() { const [theme, setTheme] = useState('light'); // ... return ( ); } ``` #### Props {/*provider-props*/} * `value`: The value that you want to pass to all the components reading this context inside this provider, no matter how deep. The context value can be of any type. A component calling [`useContext(SomeContext)`](/reference/react/useContext) inside of the provider receives the `value` of the innermost corresponding context provider above it. --- ### `SomeContext.Consumer` {/*consumer*/} Before `useContext` existed, there was an older way to read context: ```js function Button() { // 🟡 Legacy way (not recommended) return ( {theme => (