@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
24 lines (20 loc) • 607 B
JavaScript
"use client";
import { useSyncExternalStore } from "react";
//#region src/hooks/use-online/index.ts
function subscribe(callback) {
window.addEventListener("online", callback);
window.addEventListener("offline", callback);
return () => {
window.removeEventListener("online", callback);
window.removeEventListener("offline", callback);
};
}
function getSnapshot() {
return window.navigator.onLine;
}
function useOnline(getServerSnapshot = () => true) {
return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
}
//#endregion
export { useOnline };
//# sourceMappingURL=index.js.map