import { useState, useMemo, useCallback } from 'react';
import { debounce } from '../../utils/index.mjs';

const useDebouncedState = (initialValue, delay)=>{
    const [debouncedValue, setDebouncedValue] = useState(initialValue);
    const [pendingValue, setPendingValue] = useState(initialValue);
    const debouncedSetValue = useMemo(()=>debounce(setDebouncedValue, delay), [
        delay
    ]);
    const setValue = useCallback((newValue)=>{
        setPendingValue(newValue);
        debouncedSetValue(newValue);
    }, [
        debouncedSetValue
    ]);
    return [
        debouncedValue,
        setValue,
        pendingValue
    ];
};

export { useDebouncedState };
//# sourceMappingURL=useDebouncedState.mjs.map
