import { useEffect, useRef, useState } from "react";
export function useDebouncedCallback(callback, delay) {
    const [debouncedCallback, setDebouncedCallback] = useState();
    const timeout = useRef();
    useEffect(() => {
        if (!callback)
            return setDebouncedCallback(undefined);
        setDebouncedCallback(() => (...args) => {
            clearTimeout(timeout.current);
            timeout.current = setTimeout(() => callback(...args), delay);
        });
        return () => clearTimeout(timeout.current);
    }, [callback, delay]);
    return debouncedCallback;
}
//# sourceMappingURL=useDebouncedCallback.js.map