Skip to content

Commit e79120b

Browse files
committed
Clarify useLinkBuilder docs
1 parent e57d1ae commit e79120b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

versioned_docs/version-5.x/use-link-builder.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ sidebar_label: useLinkBuilder
66

77
> Note: This API is experimental and might change in a minor version.
88
9-
The `useLinkBuilder` hook let's us build a path to use for links based on a `navigate` action. It returns a function that takes `name` and `params` for the screen to navigate to and returns path based on the [`linking` options](navigation-container.md#linking).
9+
The `useLinkBuilder` hook let's us build a path to use for links for a screen in the current navigator's state. It returns a function that takes `name` and `params` for the screen to focus and returns path based on the [`linking` options](navigation-container.md#linking).
1010

1111
```js
12-
import { Link, useLinkBuilder } from '@react-navigation/native';
12+
import { Link, CommonActions, useLinkBuilder } from '@react-navigation/native';
1313

1414
// ...
1515

16-
function DrawerContent({ state, navigation, descriptors }) {
16+
function DrawerContent({ state, descriptors }) {
1717
const buildLink = useLinkBuilder();
1818

1919
return state.routes((route) => (
2020
<Link
2121
to={buildLink(route.name, route.params)}
22-
action={navigation.navigate(route.name)}
22+
action={CommonActions.navigate(route.name)}
2323
>
2424
{descriptors[route.key].options.title}
2525
</Link>
@@ -29,4 +29,7 @@ function DrawerContent({ state, navigation, descriptors }) {
2929

3030
This hook is intended to be used in navigators to show links to various pages in it, such as drawer and tab navigators. If you're building a custom navigator, custom drawer content, custom tab bar etc. then you might want to use this hook.
3131

32-
It's important to note that `useLinkBuilder` doesn't consider bubbling of the `navigate` action when building the link. So the screen to navigate to must be present in the navigator it's used in. For example, in the above case, the navigator containing `Home` should also contain the `Profile` screen.
32+
There are couple of important things to note:
33+
34+
- The destination screen must be present in the current navigator. It cannot be in a parent navigator or a navigator nested in a child.
35+
- It's intended to be only used in custom navigators to keep them reusable in multiple apps. For your regular app code, use paths directly instead of building paths for screens.

versioned_docs/version-5.x/web-support.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Currently, the following features are available:
1313
- [URL integration in browser](configuring-links.md)
1414
- [Accessible links](link.md)
1515

16-
Some navigators are also configured differently on web or provide additional web specific features:
16+
It's important to use links as the primary way of navigation instead of navigation actions such as `navigation.navigate`. It'll ensure that your links are properly usable on web.
17+
18+
Some of the navigators are also configured differently on web or provide additional web specific features:
1719

1820
1. The [drawer](drawer-navigator.md) and [bottom tab](bottom-tab-navigator.md) navigators show hyperlinks in the drawer sidebar and tab bar respectively.
1921
2. Swipe gestures are not available on [drawer](drawer-navigator.md) and [stack](stack-navigator.md) navigators when using on the web.

0 commit comments

Comments
 (0)