Meet useOffline π
It lets you know when the user loses their internet connection.
const isOffline = useOffline()
return isOffline
? <p>Youβre offline</p>
: <App />
So instead of your app silently breaking when the connection drops, you can show a proper offline state.
For example:
π‘ Onlineβ Show the app
π΄ Offlineβ Show an offline message or disable actions that need the network
One important thing:
useOffline does not make your app offline-first.
You still need things like caching, IndexedDB, and sync logic if you want the app to actually work offline.
β οΈ useOffline is currently experimental, so its API may change.
π Docs: Next.js Documentation

Top comments (0)