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
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/hello-react-navigation.md
+60-5Lines changed: 60 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -245,7 +245,7 @@ Now our stack has two _routes_, a `Home` route and a `Details` route. A route ca
245
245
246
246
:::warning
247
247
248
-
When using the dynamic API, the `component` prop accepts a component, not a render function. Don't pass an inline function (e.g. `component={() => <HomeScreen />}`), or your component will unmount and remount losing all state when the parent component re-renders. See [Passing additional props](#passing-additional-props) for alternatives.
248
+
When using the dynamic API, the `component` prop accepts a component, not a render function. Don't pass an inline function (e.g. `component={() => <HomeScreen />}`), or your component will unmount and remount losing all state when the parent component re-renders. See [Passing additional data](#passing-additional-data) for alternatives.
249
249
250
250
:::
251
251
@@ -493,19 +493,72 @@ export default function App() {
493
493
</TabItem>
494
494
</Tabs>
495
495
496
-
## Passing additional props
496
+
## Passing additional data
497
497
498
498
<TabsgroupId="config"queryString="config">
499
499
<TabItemvalue="static"label="Static"default>
500
500
501
-
Passing additional props to a screen is not supported in the static API.
501
+
To pass additional data to a screen, use `.with` to wrap the navigator with [React context](https://react.dev/reference/react/useContext) to pass data to the screens:
We can pass additional props to a screen with 2 approaches:
533
+
We can pass additional data to a screen with 2 approaches:
534
+
535
+
1.[React context](https://react.dev/reference/react/useContext) and wrap the navigator with a context provider to pass data to the screens (recommended):
1.[React context](https://react.dev/reference/react/useContext) and wrap the navigator with a context provider to pass data to the screens (recommended).
509
562
2. Render callback for the screen instead of specifying a `component` prop:
510
563
511
564
```js
@@ -545,6 +598,7 @@ If you are using TypeScript, you will need to specify the types accordingly. You
545
598
- Each property under screens refers to the name of the route, and the value is the component to render for the route.
546
599
- To specify what the initial route in a stack is, provide an [`initialRouteName`](navigator.md#initial-route-name) option for the navigator.
547
600
- To specify screen-specific options, we can specify an [`options`](screen-options.md#options-prop-on-screen) property, and for common options, we can specify [`screenOptions`](screen-options.md#screenoptions-prop-on-the-navigator).
601
+
- To pass additional data to a screen, we can use React context and use `.with` to wrap the navigator with a context provider to pass data to the screens.
548
602
549
603
</TabItem>
550
604
<TabItemvalue="dynamic"label="Dynamic">
@@ -554,6 +608,7 @@ If you are using TypeScript, you will need to specify the types accordingly. You
554
608
- Each [`Stack.Screen`](screen.md) component takes a [`name`](screen.md#name) prop which refers to the name of the route and [`component`](screen.md#component) prop which specifies the component to render for the route. These are the 2 required props.
555
609
- To specify what the initial route in a stack is, provide an [`initialRouteName`](navigator.md#initial-route-name) as the prop for the navigator.
556
610
- To specify screen-specific options, we can pass an [`options`](screen-options.md#options-prop-on-screen) prop to `Stack.Screen`, and for common options, we can pass [`screenOptions`](screen-options.md#screenoptions-prop-on-the-navigator) to `Stack.Navigator`.
611
+
- To pass additional data to a screen, we can either use React context and wrap the navigator with a context provider to pass data to the screens (recommended), or we can use a render callback for the screen instead of specifying a `component` prop.
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/troubleshooting.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
@@ -259,7 +259,7 @@ Example of some use cases for passing functions in params are the following:
259
259
- To pass a callback to use in a header button. This can be achieved using `navigation.setOptions` instead. See the [guide for header buttons](header-buttons.md#header-interaction-with-its-screen-component) for examples.
260
260
- To pass a callback to the next screen which it can call to pass some data back. You can usually achieve it using `popTo` instead. See [passing params to a previous screen](params.md#passing-params-to-a-previous-screen) for examples.
261
261
- To pass complex data to another screen. Instead of passing the data `params`, you can store that complex data somewhere else (like a global store), and pass an id instead. Then the screen can get the data from the global store using the id. See [what should be in params](params.md#what-should-be-in-params).
262
-
- Pass data, callbacks etc. from a parent to child screens. You can either use React Context, or pass a children callback to pass these down instead of using params. See [passing additional props](hello-react-navigation.md#passing-additional-props).
262
+
- Pass data, callbacks etc. from a parent to child screens. You can either use React Context, or pass a children callback to pass these down instead of using params. See [passing additional data](hello-react-navigation.md#passing-additional-data).
263
263
264
264
We don't generally recommend passing functions in params. But if you don't use state persistence, deep links, or use React Navigation on Web, then you can choose to ignore it. To ignore the warning, you can use `LogBox.ignoreLogs`.
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/hello-react-navigation.md
+59-4Lines changed: 59 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -255,19 +255,72 @@ export default function App() {
255
255
}
256
256
```
257
257
258
-
## Passing additional props
258
+
## Passing additional data
259
259
260
260
<TabsgroupId="config"queryString="config">
261
261
<TabItemvalue="static"label="Static"default>
262
262
263
-
Passing additional props to a screen is not supported in the static API.
263
+
To pass additional data to a screen, use `.with` to wrap the navigator with [React context](https://react.dev/reference/react/useContext) to pass data to the screens:
We can pass additional props to a screen with 2 approaches:
295
+
We can pass additional data to a screen with 2 approaches:
296
+
297
+
1.[React context](https://react.dev/reference/react/useContext) and wrap the navigator with a context provider to pass data to the screens (recommended):
1.[React context](https://react.dev/reference/react/useContext) and wrap the navigator with a context provider to pass data to the screens (recommended).
271
324
2. Render callback for the screen instead of specifying a `component` prop:
272
325
273
326
```js
@@ -316,6 +369,7 @@ Now that we have two screens, "How do we navigate from `Home` to `Details`?". Th
316
369
- Each property under screens refers to the name of the route, and the value is the component to render for the route.
317
370
- To specify what the initial route in a stack is, provide an [`initialRouteName`](navigator.md#initial-route-name) option for the navigator.
318
371
- To specify screen-specific options, we can specify an [`options`](screen-options.md#options-prop-on-screen) property, and for common options, we can specify [`screenOptions`](screen-options.md#screenoptions-prop-on-the-navigator).
372
+
- To pass additional data to a screen, we can use React context and use `.with` to wrap the navigator with a context provider to pass data to the screens.
319
373
320
374
</TabItem>
321
375
<TabItemvalue="dynamic"label="Dynamic">
@@ -325,6 +379,7 @@ Now that we have two screens, "How do we navigate from `Home` to `Details`?". Th
325
379
- Each [`Stack.Screen`](screen.md) component takes a [`name`](screen.md#name) prop which refers to the name of the route and [`component`](screen.md#component) prop which specifies the component to render for the route. These are the 2 required props.
326
380
- To specify what the initial route in a stack is, provide an [`initialRouteName`](navigator.md#initial-route-name) as the prop for the navigator.
327
381
- To specify screen-specific options, we can pass an [`options`](screen-options.md#options-prop-on-screen) prop to `Stack.Screen`, and for common options, we can pass [`screenOptions`](screen-options.md#screenoptions-prop-on-the-navigator) to `Stack.Navigator`.
382
+
- To pass additional data to a screen, we can either use React context and wrap the navigator with a context provider to pass data to the screens (recommended), or we can use a render callback for the screen instead of specifying a `component` prop.
Copy file name to clipboardExpand all lines: versioned_docs/version-8.x/troubleshooting.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
@@ -259,7 +259,7 @@ Example of some use cases for passing functions in params are the following:
259
259
- To pass a callback to use in a header button. This can be achieved using `navigation.setOptions` instead. See the [guide for header buttons](header-buttons.md#header-interaction-with-its-screen-component) for examples.
260
260
- To pass a callback to the next screen which it can call to pass some data back. You can usually achieve it using `popTo` instead. See [passing params to a previous screen](params.md#passing-params-to-a-previous-screen) for examples.
261
261
- To pass complex data to another screen. Instead of passing the data `params`, you can store that complex data somewhere else (like a global store), and pass an id instead. Then the screen can get the data from the global store using the id. See [what should be in params](params.md#what-should-be-in-params).
262
-
- Pass data, callbacks etc. from a parent to child screens. You can either use React Context, or pass a children callback to pass these down instead of using params. See [passing additional props](hello-react-navigation.md#passing-additional-props).
262
+
- Pass data, callbacks etc. from a parent to child screens. You can either use React Context, or pass a children callback to pass these down instead of using params. See [passing additional data](hello-react-navigation.md#passing-additional-data).
263
263
264
264
We don't generally recommend passing functions in params. But if you don't use state persistence, deep links, or use React Navigation on Web, then you can choose to ignore it. To ignore the warning, you can use `LogBox.ignoreLogs`.
0 commit comments