SW cache-first rewrite, React.lazy code splitting, PWA types/test stubs, install prompt, offline banner, offline queue, ChatPanel wiring. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
26 lines
738 B
TypeScript
26 lines
738 B
TypeScript
import { useEffect, useState } from "react";
|
|
|
|
/**
|
|
* Reactive online/offline status hook.
|
|
* Returns true when navigator.onLine is true (and updates reactively).
|
|
*/
|
|
export function useOnlineStatus(): boolean {
|
|
const [isOnline, setIsOnline] = useState(() =>
|
|
typeof navigator !== "undefined" ? navigator.onLine : true,
|
|
);
|
|
|
|
useEffect(() => {
|
|
const handleOnline = () => setIsOnline(true);
|
|
const handleOffline = () => setIsOnline(false);
|
|
|
|
window.addEventListener("online", handleOnline);
|
|
window.addEventListener("offline", handleOffline);
|
|
|
|
return () => {
|
|
window.removeEventListener("online", handleOnline);
|
|
window.removeEventListener("offline", handleOffline);
|
|
};
|
|
}, []);
|
|
|
|
return isOnline;
|
|
}
|