UNPKG

@hazae41/glacier

Version:

Yet another React data (re)fetching library

26 lines (23 loc) 642 B
import { useEffect } from 'react'; /** * Do a request on interval * @see useRetry for error retry * @param query * @param interval */ function useInterval(query, interval, init) { const { fetcher, ready, fetchOrThrow: fetch } = query; useEffect(() => { if (!ready) return; if (fetcher == null) return; if (!interval) return; const f = () => fetch(init).catch(console.warn); const i = setInterval(f, interval); return () => clearInterval(i); }, [ready, fetch, interval]); } export { useInterval }; //# sourceMappingURL=use-interval.mjs.map