UNPKG

@hazae41/glacier

Version:

Yet another React data (re)fetching library

28 lines (24 loc) 693 B
'use strict'; var react = require('react'); /** * Do a request when the tab is visible * @param query */ function useVisible(query, init) { const { fetcher, ready, fetchOrThrow: fetch } = query; react.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]); } exports.useVisible = useVisible; //# sourceMappingURL=use-visible.cjs.map