import { debounce } from 'lodash';
import { useMemo, useRef } from 'react';
const useDebouncedCallback = (callback, debounceBy) => {
    const debouncedCallbackRef = useRef();
    const debouncedCallback = useMemo(() => {
        if (debounceBy) {
            if (debouncedCallbackRef.current &&
                debouncedCallbackRef.current.cancel &&
                typeof debouncedCallbackRef.current.cancel === 'function')
                debouncedCallbackRef.current.cancel();
            const debounced = debounce(callback, debounceBy);
            debouncedCallbackRef.current = debounced;
            return debounced;
        }
        return callback;
    }, [callback, debounceBy]);
    return debouncedCallback;
};
export default useDebouncedCallback;
//# sourceMappingURL=useDebouncedCallback.js.map