1
0
Fork 0
fahrPool/web/components/pwa/OfflineBalken.tsx

27 lines
652 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useSyncExternalStore } from "react";
function abonnieren(callback: () => void) {
window.addEventListener("online", callback);
window.addEventListener("offline", callback);
return () => {
window.removeEventListener("online", callback);
window.removeEventListener("offline", callback);
};
}
export function OfflineBalken() {
const online = useSyncExternalStore(
abonnieren,
() => navigator.onLine,
() => true
);
if (online) return null;
return (
<div role="status" className="bg-asphalt-grey px-4 py-1 text-center text-sm text-white">
Offline – keine Verbindung
</div>
);
}