Skip to content

Commit 0c2304a

Browse files
committed
docs: Updated links in typescript.md
1 parent 79fe533 commit 0c2304a

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

versioned_docs/version-7.x/typescript.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ React Navigation can be configured to type-check screens and their params, as we
1414

1515
There are 2 steps to configure TypeScript with the static API:
1616

17-
1. Each screen component needs to specify the type of the `route.params` prop that it accepts. The `StaticScreenProps` type makes it simpler:
17+
1. Each screen component needs to specify the type of the [`route.params`](params.md) prop that it accepts. The `StaticScreenProps` type makes it simpler:
1818

1919
```ts
2020
import type { StaticScreenProps } from '@react-navigation/native';
@@ -64,7 +64,7 @@ There are 2 steps to configure TypeScript with the static API:
6464

6565
## Navigator specific types
6666

67-
Generally, we recommend using the default types for the `useNavigation` prop to access the navigation object in a navigator-agnostic manner. However, if you need to use navigator-specific APIs, you need to manually annotate `useNavigation`:
67+
Generally, we recommend using the default types for the [`useNavigation`](use-navigation.md) prop to access the navigation object in a navigator-agnostic manner. However, if you need to use navigator-specific APIs, you need to manually annotate [`useNavigation`](use-navigation.md):
6868

6969
```ts
7070
type BottomTabParamList = StaticParamList<typeof BottomTabNavigator>;
@@ -78,7 +78,7 @@ type ProfileScreenNavigationProp = BottomTabNavigationProp<
7878
const navigation = useNavigation<ProfileScreenNavigationProp>();
7979
```
8080

81-
Note that annotating `useNavigation` this way is not type-safe since we can't guarantee that the type you provided matches the type of the navigator.
81+
Note that annotating [`useNavigation`](use-navigation.md) this way is not type-safe since we can't guarantee that the type you provided matches the type of the navigator.
8282

8383
## Nesting navigator using dynamic API
8484

@@ -103,7 +103,7 @@ const RootStack = createStackNavigator({
103103

104104
Here, the `HomeTabs` component is defined using the dynamic API. This means that when we create the param list for the root navigator with `StaticParamList<typeof RootStack>`, it won't know about the screens defined in the nested navigator. To fix this, we'd need to specify the param list for the nested navigator explicitly.
105105

106-
This can be done by using the type of the `route` prop that the screen component receives:
106+
This can be done by using the type of the [`route`](route-object.md) prop that the screen component receives:
107107

108108
```ts
109109
type HomeTabsParamList = {
@@ -157,7 +157,7 @@ type RootStackParamList = {
157157

158158
Specifying `undefined` means that the route doesn't have params. A union type with `undefined` (e.g. `SomeType | undefined`) means that params are optional.
159159

160-
After we have defined the mapping, we need to tell our navigator to use it. To do that, we can pass it as a generic to the `createXNavigator` functions:
160+
After we have defined the mapping, we need to tell our navigator to use it. To do that, we can pass it as a generic to the [`createXNavigator`](static-configuration.md) functions:
161161

162162
```tsx
163163
import { createStackNavigator } from '@react-navigation/stack';
@@ -179,7 +179,7 @@ And then we can use it:
179179
</RootStack.Navigator>
180180
```
181181

182-
This will provide type checking and intelliSense for props of the `Navigator` and `Screen` components.
182+
This will provide type checking and intelliSense for props of the [`Navigator`](navigator.md) and [`Screen`](screen.md) components.
183183

184184
:::note
185185

@@ -217,9 +217,9 @@ If you have an `id` prop for your navigator, you can do:
217217
type Props = NativeStackScreenProps<RootStackParamList, 'Profile', 'MyStack'>;
218218
```
219219

220-
This allows us to type check route names and params which you're navigating using `navigate`, `push` etc. The name of the current route is necessary to type check the params in `route.params` and when you call [`setParams`](navigation-actions#setparams).
220+
This allows us to type check route names and params which you're navigating using [`navigate`](navigation-object.md#navigate), [`push`](stack-actions.md#push) etc. The name of the current route is necessary to type check the params in `route.params` and when you call [`setParams`](navigation-actions#setparams).
221221

222-
Similarly, you can import `StackScreenProps` for `@react-navigation/stack`, `DrawerScreenProps` from `@react-navigation/drawer`, `BottomTabScreenProps` from `@react-navigation/bottom-tabs` and so on.
222+
Similarly, you can import `StackScreenProps` from [`@react-navigation/stack`](stack-navigator.md), `DrawerScreenProps` from [`@react-navigation/drawer`](drawer-navigator.md), `BottomTabScreenProps` from [`@react-navigation/bottom-tabs`](bottom-tab-navigator.md) and so on.
223223

224224
Then you can use the `Props` type you defined above to annotate your component.
225225

@@ -262,7 +262,7 @@ type ProfileScreenNavigationProp = NativeStackNavigationProp<
262262
>;
263263
```
264264

265-
Similarly, you can import `StackNavigationProp` from `@react-navigation/stack`, `DrawerNavigationProp` from `@react-navigation/drawer`, `BottomTabNavigationProp` from `@react-navigation/bottom-tabs` etc.
265+
Similarly, you can import `StackNavigationProp` from [`@react-navigation/stack`](stack-navigator.md), `DrawerNavigationProp` from [`@react-navigation/drawer`](drawer-navigator.md), `BottomTabNavigationProp` from [`@react-navigation/bottom-tabs`](bottom-tab-navigator.md) etc.
266266

267267
To get the type for the `route` object, we need to use the `RouteProp` type from `@react-navigation/native`:
268268

@@ -300,7 +300,7 @@ type TabParamList = {
300300

301301
### Combining navigation props
302302

303-
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:
303+
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:
304304

305305
```ts
306306
import type { CompositeScreenProps } from '@react-navigation/native';
@@ -349,7 +349,7 @@ Prefer [specifying a default type](#specifying-default-types-for-usenavigation-l
349349

350350
:::
351351

352-
To annotate the `navigation` object that we get from `useNavigation`, we can use a type parameter:
352+
To annotate the `navigation` object that we get from [`useNavigation`](use-navigation.md), we can use a type parameter:
353353

354354
```ts
355355
const navigation = useNavigation<ProfileScreenNavigationProp>();
@@ -364,7 +364,7 @@ Prefer using the [`route` object](route-object.md) from the screen component's p
364364

365365
:::
366366

367-
To annotate the `route` object that we get from `useRoute`, we can use a type parameter:
367+
To annotate the `route` object that we get from [`useRoute`](use-route.md), we can use a type parameter:
368368

369369
```ts
370370
const route = useRoute<ProfileScreenRouteProp>();
@@ -463,13 +463,13 @@ declare global {
463463

464464
The `RootParamList` interface lets React Navigation know about the params accepted by your root navigator. Here we extend the type `RootStackParamList` because that's the type of params for our stack navigator at the root. The name of this type isn't important.
465465

466-
Specifying this type is important if you heavily use `useNavigation`, `Link` etc. in your app since it'll ensure type-safety. It will also make sure that you have correct nesting on the `linking` prop.
466+
Specifying this type is important if you heavily use [`useNavigation`](use-navigation.md), [`Link`](link.md) etc. in your app since it'll ensure type-safety. It will also make sure that you have correct nesting on the [`linking`](navigation-container.md#linking) prop.
467467

468468
## Organizing types
469469

470470
When writing types for React Navigation, there are a couple of things we recommend to keep things organized.
471471

472-
1. It's good to create a separate file (e.g. `navigation/types.tsx`) that contains the types related to React Navigation.
472+
1. It's good to create a separate file (e.g. `navigation/types.ts`) that contains the types related to React Navigation.
473473
2. Instead of using `CompositeNavigationProp` directly in your components, it's better to create a helper type that you can reuse.
474474
3. Specifying a global type for your root navigator would avoid manual annotations in many places.
475475

@@ -520,7 +520,7 @@ function PopularScreen({ navigation, route }: HomeTabScreenProps<'Popular'>) {
520520
}
521521
```
522522

523-
If you're using hooks such as `useRoute`, you can write:
523+
If you're using hooks such as [`useRoute`](use-route.md), you can write:
524524

525525
```ts
526526
import type { HomeTabScreenProps } from './navigation/types';

0 commit comments

Comments
 (0)