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-6.x/typescript.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -171,7 +171,9 @@ type TabParamList = {
171
171
172
172
#### Combining navigation props
173
173
174
-
When you nest navigators, the navigation prop of the screen is a combination of multiple navigation props. For example, if we have a tab inside a stack, the `navigation` prop will have both `jumpTo` (from the tab navigator) and `push` (from the stack navigator). To make it easier to combine types from multiple navigators, you can use the `CompositeScreenProps` type:
174
+
When you nest navigators, the navigation prop of the screen is a combination of multiple navigation props. For example, if we have a tab inside a stack, the `navigation` prop will have both [`jumpTo`](tab-actions.md#jumpto) (from the tab navigator) and [`push`](stack-actions.md#push) (from the stack navigator). To make it easier to combine types from multiple navigators, you can use the `CompositeScreenProps` type.
175
+
176
+
For example, if we have a `Profile` in a navigator, nested inside `Account` screen of a stack navigator, we can combine the types as follows:
@@ -180,20 +182,23 @@ import type { StackScreenProps } from '@react-navigation/stack';
180
182
181
183
typeProfileScreenProps=CompositeScreenProps<
182
184
BottomTabScreenProps<TabParamList, 'Profile'>,
183
-
StackScreenProps<StackParamList>
185
+
StackScreenProps<StackParamList, 'Account'>
184
186
>;
185
187
```
186
188
187
-
The `CompositeScreenProps` type takes 2 parameters, first parameter is the type of props for the primary navigation (type for the navigator that owns this screen, in our case the tab navigator which contains the `Profile` screen) and second parameter is the type of props for secondary navigation (type for a parent navigator). The primary type should always have the screen's route name as its second parameter.
189
+
The `CompositeScreenProps` type takes 2 parameters:
190
+
191
+
- The first parameter is the type for the navigator that owns this screen, in our case the tab navigator which contains the `Profile` screen
192
+
- The second parameter is the type of props for a parent navigator, in our case the stack navigator which contains the `Account` screen
188
193
189
-
For multiple parent navigators, this secondary type should be nested:
194
+
For multiple parent navigators, this second parameter can nest another `CompositeScreenProps`:
190
195
191
196
```ts
192
197
typeProfileScreenProps=CompositeScreenProps<
193
198
BottomTabScreenProps<TabParamList, 'Profile'>,
194
199
CompositeScreenProps<
195
-
StackScreenProps<StackParamList>,
196
-
DrawerScreenProps<DrawerParamList>
200
+
StackScreenProps<StackParamList, 'Account'>,
201
+
DrawerScreenProps<DrawerParamList, 'Home'>
197
202
>
198
203
>;
199
204
```
@@ -207,7 +212,7 @@ import type { StackNavigationProp } from '@react-navigation/stack';
Copy file name to clipboardExpand all lines: versioned_docs/version-7.x/typescript.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -319,7 +319,9 @@ type TabParamList = {
319
319
320
320
### Combining navigation props
321
321
322
-
When you nest navigators, the navigation prop of the screen is a combination of multiple navigation props. For example, if we have a tab inside a stack, the `navigation` prop will have both [`jumpTo`](tab-actions.md#jumpto) (from the tab navigator) and [`push`](stack-actions.md#push) (from the stack navigator). To make it easier to combine types from multiple navigators, you can use the `CompositeScreenProps` type:
322
+
When you nest navigators, the navigation prop of the screen is a combination of multiple navigation props. For example, if we have a tab inside a stack, the `navigation` prop will have both [`jumpTo`](tab-actions.md#jumpto) (from the tab navigator) and [`push`](stack-actions.md#push) (from the stack navigator). To make it easier to combine types from multiple navigators, you can use the `CompositeScreenProps` type.
323
+
324
+
For example, if we have a `Profile` in a navigator, nested inside `Account` screen of a stack navigator, we can combine the types as follows:
@@ -328,20 +330,23 @@ import type { StackScreenProps } from '@react-navigation/stack';
328
330
329
331
typeProfileScreenProps=CompositeScreenProps<
330
332
BottomTabScreenProps<TabParamList, 'Profile'>,
331
-
StackScreenProps<StackParamList>
333
+
StackScreenProps<StackParamList, 'Account'>
332
334
>;
333
335
```
334
336
335
-
The `CompositeScreenProps` type takes 2 parameters, the first parameter is the type of props for the primary navigation (type for the navigator that owns this screen, in our case the tab navigator which contains the `Profile` screen) and the second parameter is the type of props for secondary navigation (type for a parent navigator). The primary type should always have the screen's route name as its second parameter.
337
+
The `CompositeScreenProps` type takes 2 parameters:
338
+
339
+
- The first parameter is the type for the navigator that owns this screen, in our case the tab navigator which contains the `Profile` screen
340
+
- The second parameter is the type of props for a parent navigator, in our case the stack navigator which contains the `Account` screen
336
341
337
-
For multiple parent navigators, this secondary type should be nested:
342
+
For multiple parent navigators, this second parameter can nest another `CompositeScreenProps`:
338
343
339
344
```ts
340
345
typeProfileScreenProps=CompositeScreenProps<
341
346
BottomTabScreenProps<TabParamList, 'Profile'>,
342
347
CompositeScreenProps<
343
-
StackScreenProps<StackParamList>,
344
-
DrawerScreenProps<DrawerParamList>
348
+
StackScreenProps<StackParamList, 'Account'>,
349
+
DrawerScreenProps<DrawerParamList, 'Home'>
345
350
>
346
351
>;
347
352
```
@@ -355,7 +360,7 @@ import type { StackNavigationProp } from '@react-navigation/stack';
0 commit comments