mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-06 08:15:45 +00:00
22 lines
675 B
TypeScript
22 lines
675 B
TypeScript
"use client";
|
|
|
|
import { useSyncExternalStore } from "react";
|
|
|
|
function subscribe(onChange: () => void): () => void {
|
|
window.addEventListener("online", onChange);
|
|
window.addEventListener("offline", onChange);
|
|
return () => {
|
|
window.removeEventListener("online", onChange);
|
|
window.removeEventListener("offline", onChange);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Whether the browser says it has a network, kept up to date. Also without
|
|
* offline mode, whose store only follows it while that runs. True on the
|
|
* server and while the page hydrates.
|
|
*/
|
|
export function useBrowserOnline(): boolean {
|
|
return useSyncExternalStore(subscribe, () => navigator.onLine !== false, () => true);
|
|
}
|