Skip to content

Commit 5927c4e

Browse files
Replace Context.Provider with Context (#7838)
Update to be in line with the recommended way from React 19. Docs https://react.dev/blog/2024/12/05/react-19#context-as-a-provider --------- Co-authored-by: Ricky <[email protected]>
1 parent 37b09ea commit 5927c4e

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

src/content/learn/managing-state.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -837,9 +837,7 @@ export function TasksProvider({ children }) {
837837

838838
return (
839839
<TasksContext value={tasks}>
840-
<TasksDispatchContext
841-
value={dispatch}
842-
>
840+
<TasksDispatchContext value={dispatch}>
843841
{children}
844842
</TasksDispatchContext>
845843
</TasksContext>

src/content/learn/scaling-up-with-reducer-and-context.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1363,4 +1363,3 @@ As your app grows, you may have many context-reducer pairs like this. This is a
13631363
- You can have many context-reducer pairs like this in your app.
13641364
13651365
</Recap>
1366-

src/content/reference/react/createContext.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const ThemeContext = createContext('light');
4646

4747
---
4848

49-
### `SomeContext` {/*provider*/}
49+
### `SomeContext` Provider {/*provider*/}
5050

5151
Wrap your components into a context provider to specify the value of this context for all components inside:
5252

@@ -62,6 +62,14 @@ function App() {
6262
}
6363
```
6464

65+
<Note>
66+
67+
Starting in React 19, you can render `<SomeContext>` as a provider.
68+
69+
In older versions of React, use `<SomeContext.Provider>`.
70+
71+
</Note>
72+
6573
#### Props {/*provider-props*/}
6674

6775
* `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.
@@ -215,4 +223,3 @@ const ThemeContext = createContext('light');
215223
This value never changes. React only uses this value as a fallback if it can't find a matching provider above.
216224

217225
To make context change over time, [add state and wrap components in a context provider.](/reference/react/useContext#updating-data-passed-via-context)
218-

src/content/reference/react/legacy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ These APIs were removed in React 19:
3030
* [`createFactory`](https://18.react.dev/reference/react/createFactory): use JSX instead.
3131
* Class Components: [`static contextTypes`](https://18.react.dev//reference/react/Component#static-contexttypes): use [`static contextType`](#static-contexttype) instead.
3232
* 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.
3434
* Class Components: [`static propTypes`](https://18.react.dev//reference/react/Component#static-proptypes): use a type system like [TypeScript](https://www.typescriptlang.org/) instead.
3535
* Class Components: [`this.refs`](https://18.react.dev//reference/react/Component#refs): use [`createRef`](/reference/react/createRef) instead.

0 commit comments

Comments
 (0)