useOffline
API Reference for the useOffline hook.
The useOffline hook returns a boolean indicating whether the app is currently offline. Use it to render connectivity-aware UI, such as a banner when the user loses their network connection, or an offline-aware Suspense fallback.
The hook is one piece of a larger feature. Enabling the experimental.useOffline config option turns on offline connectivity detection and automatic retry of blocked navigation, prefetch, and Server Action requests, and exposes this hook so Client Components can read the state.
Without the flag, this hook always returns false.
For details on how connectivity is detected and requests retried, see How retry works.
Parameters
useOffline does not take any parameters.
Returns
useOffline returns a boolean:
| Value | Meaning |
|---|---|
true | The app is offline. A network request has failed, or the browser has fired an offline event. |
false | The app is online, or rendering on the server. This is also the initial value before hydration completes. |
Examples
Show an offline banner
Render a persistent banner whenever the user loses connectivity.
Render it in the root layout so the banner shows on every route:
Offline-aware Suspense fallback
When a user navigates to a route while offline, the prefetched static shell renders immediately but the dynamic content behind a <Suspense> boundary blocks on the network. For example, use useOffline inside a loading.tsx file to explain why the content is taking longer than expected.
When connectivity is restored, Next.js retries the blocked request and the dynamic content streams in automatically.
Version History
| Version | Changes |
|---|---|
v16.x.0 | useOffline hook introduced. |