UNPKG

@hazae41/glacier

Version:

Yet another React data (re)fetching library

28 lines (24 loc) 669 B
'use strict'; var react = require('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; react.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]); } exports.useInterval = useInterval; //# sourceMappingURL=use-interval.cjs.map