Skip to content
On this page
Browser & DOMClient Component

useOnline

Overview

useOnline observes browser online and offline events and exposes navigator.onLine as a React external-store snapshot.

Signature

ts
function useOnline(): boolean;

Parameters

This Hook takes no parameters.

Returns

false only when the browser reports navigator.onLine === false; otherwise true.

Behavior

Subscribers in one browser realm share a single listener pair. The listeners and cached store are removed after the last subscriber unmounts.

SSR / RSC

The server snapshot is true. Connectivity is a browser hint, not proof that a specific endpoint is reachable. Use the Hook in a Client Component.

Example

Composition

Use it to pause useInterval polling or explain an error; still handle request failures through useAsync.

Source

Read the implementation on GitHub.