import { useRef, useState } from 'react';
import { useDebouncedCallback } from './debounced-callback';
import { useEvent } from './event';
export function useDebouncedState(initialState, delay, maxWait = 0) {
    const [state, setState] = useState(initialState);
    const currentValueRef = useRef(state);
    const dSetState = useDebouncedCallback(setState, [], delay, maxWait);
    const setValue = useEvent((next) => {
        currentValueRef.current = next instanceof Function ? next(currentValueRef.current) : next;
        void dSetState(currentValueRef.current);
    });
    return [state, setValue];
}
//# sourceMappingURL=debounced-state.js.map