forked from fahrPool/fahrPool
27 lines
652 B
TypeScript
27 lines
652 B
TypeScript
"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>
|
||
);
|
||
}
|