UNPKG

@hazae41/glacier

Version:

Yet another React data (re)fetching library

26 lines (23 loc) 667 B
import { useEffect } from 'react'; /** * Do a request when the tab is visible * @param query */ function useVisible(query, init) { const { fetcher, ready, fetchOrThrow: fetch } = query; useEffect(() => { if (!ready) return; if (fetcher == null) return; const f = () => { if (document.hidden) return; fetch(init).catch(console.warn); }; document.addEventListener("visibilitychange", f); return () => document.removeEventListener("visibilitychange", f); }, [ready, fetch]); } export { useVisible }; //# sourceMappingURL=use-visible.mjs.map