UNPKG

@stolostron/multicluster-sdk

Version:

Provides extensions and APIs that dynamic plugins can use to leverage multicluster capabilities provided by Red Hat Advanced Cluster Management.

27 lines 1.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.usePoll = void 0; /* Copyright Contributors to the Open Cluster Management project */ const react_1 = require("react"); // Slightly modified from Dan Abramov's blog post about using React hooks for polling // https://overreacted.io/making-setinterval-declarative-with-react-hooks/ const usePoll = (callback, delay, ...dependencies) => { const savedCallback = (0, react_1.useRef)(null); // Remember the latest callback. (0, react_1.useEffect)(() => { savedCallback.current = callback; }, [callback]); // Set up the interval. (0, react_1.useEffect)(() => { const tick = () => savedCallback.current(); tick(); // Run first tick immediately. if (delay) { // Only start interval if a delay is provided. const id = setInterval(tick, delay); return () => clearInterval(id); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [delay, ...dependencies]); }; exports.usePoll = usePoll; //# sourceMappingURL=usePoll.js.map