| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.useInterval = void 0; |
| 4 |
/** This is a custom React hook in a format suggest by Dan Abramov in a blog post here: |
| 5 |
* https://overreacted.io/making-setinterval-declarative-with-react-hooks/. It allows setInterval to be used |
| 6 |
* declaratively in functional React components. |
| 7 |
*/ |
| 8 |
const react_1 = require("react"); |
| 9 |
function useInterval(callback, delay) { |
| 10 |
const savedCallback = (0, react_1.useRef)(() => { }); |
| 11 |
(0, react_1.useEffect)(() => { |
| 12 |
savedCallback.current = callback; |
| 13 |
}, [callback]); |
| 14 |
(0, react_1.useEffect)(() => { |
| 15 |
function tick() { |
| 16 |
savedCallback.current(); |
| 17 |
} |
| 18 |
if (delay !== null) { |
| 19 |
const id = setInterval(tick, delay); |
| 20 |
return () => clearInterval(id); |
| 21 |
} |
| 22 |
}, [delay]); |
| 23 |
} |
| 24 |
exports.useInterval = useInterval; |
| 25 |
//# sourceMappingURL=useInterval.js.map |