You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**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:
41
+
**The context object itself does not hold any information.** It represents _which_ context other components read or provide. Typically, you will use [`SomeContext`](#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:
42
42
43
-
*`SomeContext.Provider` lets you provide the context value to components.
43
+
*`SomeContext` lets you provide the context value to components.
44
+
*`SomeContext.Provider` a legacy way to provide the context value.
44
45
*`SomeContext.Consumer` is an alternative and rarely used way to read the context value.
45
46
46
47
---
47
48
48
-
### `SomeContext.Provider` {/*provider*/}
49
+
### `SomeContext` or `SomeContext.Provider` {/*provider*/}
49
50
50
51
Wrap your components into a context provider to specify the value of this context for all components inside:
51
52
@@ -54,13 +55,15 @@ function App() {
54
55
const [theme, setTheme] =useState('light');
55
56
// ...
56
57
return (
57
-
<ThemeContext.Provider value={theme}>
58
+
<ThemeContext value={theme}>
58
59
<Page />
59
-
</ThemeContext.Provider>
60
+
</ThemeContext>
60
61
);
61
62
}
62
63
```
63
64
65
+
`SomeContext.Provider` is an alias for `SomeContext` and was used in older versions of React before 19.0.
66
+
64
67
#### Props {/*provider-props*/}
65
68
66
69
*`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.
Copy file name to clipboardExpand all lines: src/content/reference/react/legacy.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,6 @@ These APIs were removed in React 19:
30
30
*[`createFactory`](https://18.react.dev/reference/react/createFactory): use JSX instead.
31
31
* Class Components: [`static contextTypes`](https://18.react.dev//reference/react/Component#static-contexttypes): use [`static contextType`](#static-contexttype) instead.
32
32
* Class Components: [`static childContextTypes`](https://18.react.dev//reference/react/Component#static-childcontexttypes): use [`static contextType`](#static-contexttype) instead.
33
-
* Class Components: [`static getChildContext`](https://18.react.dev//reference/react/Component#getchildcontext): use [`Context.Provider`](/reference/react/createContext#provider) instead.
33
+
* Class Components: [`static getChildContext`](https://18.react.dev//reference/react/Component#getchildcontext): use [`Context`](/reference/react/createContext#provider) instead.
34
34
* Class Components: [`static propTypes`](https://18.react.dev//reference/react/Component#static-proptypes): use a type system like [TypeScript](https://www.typescriptlang.org/) instead.
35
35
* Class Components: [`this.refs`](https://18.react.dev//reference/react/Component#refs): use [`createRef`](/reference/react/createRef) instead.
0 commit comments