import { useState } from 'react'; import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect'; var useRaf = function (ms, delay) { if (ms === void 0) { ms = 1e12; } if (delay === void 0) { delay = 0; } var _a = useState(0), elapsed = _a[0], set = _a[1]; useIsomorphicLayoutEffect(function () { var raf; var timerStop; var start; var onFrame = function () { var time = Math.min(1, (Date.now() - start) / ms); set(time); loop(); }; var loop = function () { raf = requestAnimationFrame(onFrame); }; var onStart = function () { timerStop = setTimeout(function () { cancelAnimationFrame(raf); set(1); }, ms); start = Date.now(); loop(); }; var timerDelay = setTimeout(onStart, delay); return function () { clearTimeout(timerStop); clearTimeout(timerDelay); cancelAnimationFrame(raf); }; }, [ms, delay]); return elapsed; }; export default useRaf;