@hazae41/glacier
Version:
Yet another React data (re)fetching library
22 lines (19 loc) • 547 B
JavaScript
import { useEffect } from 'react';
/**
* Do a request when the browser is online
* @param query
*/
function useOnline(query, init) {
const { fetcher, ready, fetchOrThrow: fetch } = query;
useEffect(() => {
if (!ready)
return;
if (fetcher == null)
return;
const f = () => fetch(init).catch(console.warn);
addEventListener("online", f);
return () => removeEventListener("online", f);
}, [ready, fetch]);
}
export { useOnline };
//# sourceMappingURL=use-online.mjs.map