import { b as reactExports, dW as useBrowserLayoutEffect } from './index-Cy6GwrlT.js';

// Inspired by https://usehooks-ts.com/react-hook/use-interval
function useInterval(callback, delay) {
    const savedCallback = reactExports.useRef(callback);
    const interval = reactExports.useRef(0);
    // Remember the latest callback if it changes.
    useBrowserLayoutEffect(() => {
        savedCallback.current = callback;
    }, [callback]);
    // Set up the interval.
    reactExports.useEffect(() => {
        // Don't schedule if no delay is specified.
        // Note: 0 is a valid value for delay.
        if (!delay && delay !== 0) {
            return;
        }
        interval.current = setInterval(() => savedCallback.current(), delay);
        // eslint-disable-next-line consistent-return
        return () => { clearInterval(interval.current); };
    }, [delay]);
    return () => {
        if (interval.current) {
            clearInterval(interval.current);
        }
    };
}

export { useInterval as u };
