useOnlineStatus
function useOnlineStatus(): boolean;
Returns navigator.onLine and re-renders on the browser's online and offline events.
false means the browser has no network connection at all; true does not guarantee a
request will succeed. During server rendering, and on the first render while hydrating, it
returns true.
Live demo
Online
Turn off your Wi-Fi, or go offline in your browser's dev tools.
Example
import { useOnlineStatus } from "react-honey-hooks";
function SaveButton({ onSave }: { onSave: () => void }) {
const online = useOnlineStatus();
return (
<button disabled={!online} onClick={onSave}>
{online ? "Save" : "Offline: changes will sync later"}
</button>
);
}