Skip to Content
HooksuseNetworkState

useNetworkState

Tracks the browser’s online/offline status. SSR-safe — returns { online: defaultOnline } (default true) on the server. since is the time of the last status change, or undefined until the first transition

Status: online ✅
Last change: — (no change yet)

Toggle your network (or DevTools → Offline) to see it react.

import { useNetworkState } from 'react-stateful-hooks'; const { online, since } = useNetworkState(); if (!online) return <Banner>You are offline.</Banner>;

Signature

const { online, since } = useNetworkState(defaultOnline?: boolean); // default: true
FieldDescription
onlinetrue when the browser reports connectivity
sinceDate of the last online/offline transition, or undefined
Last updated on