"use client"; import { useEffect, useState } from "react"; /** True while the browser reports a connection. Starts optimistic (SSR). */ export function useOnline(): boolean { const [online, setOnline] = useState(true); useEffect(() => { const sync = () => setOnline(navigator.onLine); sync(); window.addEventListener("online", sync); window.addEventListener("offline", sync); return () => { window.removeEventListener("online", sync); window.removeEventListener("offline", sync); }; }, []); return online; }