Skip to content

Commit 5a892f8

Browse files
committed
Document NavigationProvider
1 parent 39e18a6 commit 5a892f8

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

versioned_docs/version-8.x/upgrading-from-7.x.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,30 @@ export default function App() {
931931

932932
See [State persistence docs](state-persistence.md) for more details.
933933

934+
### `NavigationProvider` lets you provide `navigation` and `route` objects
935+
936+
Previously, to provide the `navigation` and `route` objects to your custom components, it was necessary to use `NavigationContext.Provider` and `NavigationRouteContext.Provider` respectively.
937+
938+
There is now a new `NavigationProvider` component that consolidates them, and adds support for [accessing route by screen name](#common-hooks-now-accept-name-of-the-screen) with `useRoute`:
939+
940+
```diff lang=js
941+
- import { NavigationContext, NavigationRouteContext } from '@react-navigation/native';
942+
+ import { NavigationProvider } from '@react-navigation/native';
943+
944+
// ...
945+
946+
- <NavigationContext.Provider value={navigation}>
947+
- <NavigationRouteContext.Provider value={route}>
948+
- {/* ... */}
949+
- </NavigationRouteContext.Provider>
950+
- </NavigationContext.Provider>
951+
+ <NavigationProvider navigation={navigation} route={route}>
952+
+ {/* ... */}
953+
+ </NavigationProvider>
954+
```
955+
956+
This is only necessary if you have custom components rendered in a navigator, e.g. buttons in a custom tab bar. Components rendered as part of a screen will have access to the `navigation` and `route` objects without any additional setup.
957+
934958
### `Header` from `@react-navigation/elements` has been reworked
935959

936960
The `Header` component from `@react-navigation/elements` has been reworked with various improvements:

0 commit comments

Comments
 (0)