Skip to Content
ohooks

useOnline

Tracks whether the browser is currently connected to the network (navigator.onLine) using useSyncExternalStore.

Loading preview...

The useOnline hook subscribes to window online and offline events via useSyncExternalStore and returns a boolean reflecting navigator.onLine (defaulting to true during SSR).

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useOnline.json

Usage

Examples

Offline Banner Notification

Display a status banner whenever the user loses network connectivity.

Disabling Network Actions While Offline

Prevent form submission buttons from firing while the browser is disconnected.