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: docs/01-app/05-api-reference/04-functions/use-link-status.mdx
+90-78Lines changed: 90 additions & 78 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,20 @@
1
1
---
2
2
title: useLinkStatus
3
3
description: API Reference for the useLinkStatus hook.
4
+
related:
5
+
title: Next Steps
6
+
description: Learn more about the features mentioned in this page by reading the API Reference.
7
+
links:
8
+
- app/api-reference/components/link
9
+
- app/api-reference/file-conventions/loading
4
10
---
5
11
6
-
`useLinkStatus` is a **Client Component** hook that lets you track the loading state of a `Link` component during navigation. It can be used to show loading indicators during page transitions, especially when [prefetching](/docs/app/building-your-application/routing/linking-and-navigating#2-prefetching) is disabled, or the linked route does not have any loading states.
12
+
The `useLinkStatus` hook lets you tracks the **pending** state of a `<Link>`. You can use it to show inline visual feedback to the user (like spinners or text glimmers) while a navigation to a new route completes.
13
+
14
+
`useLinkStatus` is useful when:
15
+
16
+
-[Prefetching](/docs/app/building-your-application/routing/linking-and-navigating#2-prefetching) is disabled or in progress meaning navigation is blocked.
17
+
- The destination route is dynamic **and** doesn't include a [`loading.js`](/docs/app/api-reference/file-conventions/loading) file that would allow an instant navigation.
| pending | boolean |`true` before history updates, `false` after |
83
98
84
-
## Examples
85
-
86
-
### Improving the user experience when navigating with new query parameters
99
+
## Example
87
100
88
-
In this example, navigating between categories updates the query string (e.g. ?category=books). However, the page may appear unresponsive because the `<PageSkeleton />` fallback won't replace the existing content (see [preventing unwanted loading indicators](https://react.dev/reference/react/useTransition#preventing-unwanted-loading-indicators)).
101
+
### Inline loading indicator
89
102
90
-
You can use the `useLinkStatus` hook to render a lightweight loading indicator next to the active link and provide immediate feedback to the user while the data is being fetched.
103
+
It's helpful to add visual feedback that navigation is happening in case the user clicks a link before prefetching is complete.
If the navigation to a new route is fast, users may see an unecessary flash of the loading indicator. One way to improve the user experience and only show the loading indicator when the navigation takes time to complete is to add an initial animation delay (e.g. 100ms) and start the animation as invisible (e.g. `opacity: 0`).
0 commit comments