import { useEffect, useRef } from 'react';
/**
 * heavily inspired by @dan_abramov's post
 *
 * @see https://overreacted.io/making-setinterval-declarative-with-react-hooks/
 */
export const useInterval = (handler, timeout) => {
    const handlerRef = useRef();
    useEffect(() => {
        handlerRef.current = handler;
    }, [handler]);
    useEffect(() => {
        if (timeout === null) {
            return;
        }
        const intervalId = setInterval(() => {
            var _a;
            typeof handlerRef.current === 'function' && ((_a = handlerRef.current) === null || _a === void 0 ? void 0 : _a.call(handlerRef));
        }, timeout);
        return () => clearInterval(intervalId);
    }, [timeout]);
};
//# sourceMappingURL=useInterval.js.map