source: imaps-frontend/node_modules/react-use/esm/useRaf.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[d565449]1import { useState } from 'react';
2import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
3var useRaf = function (ms, delay) {
4 if (ms === void 0) { ms = 1e12; }
5 if (delay === void 0) { delay = 0; }
6 var _a = useState(0), elapsed = _a[0], set = _a[1];
7 useIsomorphicLayoutEffect(function () {
8 var raf;
9 var timerStop;
10 var start;
11 var onFrame = function () {
12 var time = Math.min(1, (Date.now() - start) / ms);
13 set(time);
14 loop();
15 };
16 var loop = function () {
17 raf = requestAnimationFrame(onFrame);
18 };
19 var onStart = function () {
20 timerStop = setTimeout(function () {
21 cancelAnimationFrame(raf);
22 set(1);
23 }, ms);
24 start = Date.now();
25 loop();
26 };
27 var timerDelay = setTimeout(onStart, delay);
28 return function () {
29 clearTimeout(timerStop);
30 clearTimeout(timerDelay);
31 cancelAnimationFrame(raf);
32 };
33 }, [ms, delay]);
34 return elapsed;
35};
36export default useRaf;
Note: See TracBrowser for help on using the repository browser.