Debian Codegraph @

node/@patternfly/react-core/dist/esm/helpers/useInterval.js

raw
1 /** This is a custom React hook in a format suggest by Dan Abramov in a blog post here:
2 * https://overreacted.io/making-setinterval-declarative-with-react-hooks/. It allows setInterval to be used
3 * declaratively in functional React components.
4 */
5 import { useEffect, useRef } from 'react';
6 export function useInterval(callback, delay) {
7 const savedCallback = useRef(() => { });
8 useEffect(() => {
9 savedCallback.current = callback;
10 }, [callback]);
11 useEffect(() => {
12 function tick() {
13 savedCallback.current();
14 }
15 if (delay !== null) {
16 const id = setInterval(tick, delay);
17 return () => clearInterval(id);
18 }
19 }, [delay]);
20 }
21 //# sourceMappingURL=useInterval.js.map