Skip to content

Commit 4027655

Browse files
committed
Replace Context.Provider with Context
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
1 parent c60173f commit 4027655

File tree

4 files changed

+5
-7
lines changed

4 files changed

+5
-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: 3 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` and `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,8 @@ function App() {
6262
}
6363
```
6464

65+
`SomeContext.Provider` is an alias for `SomeContext` and was used in older versions of React before 19.0.
66+
6567
#### Props {/*provider-props*/}
6668

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

217219
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)