import { useState } from 'react'; import { debounce } from 'debounce'; type DebounceFn = ((value: V) => void) & { clear: () => void }; export default (initial: S, interval?: number, immediate?: boolean): [S, DebounceFn] => { const [state, setState] = useState(initial); const debouncedSetState = debounce((v: S) => setState(v), interval, immediate); return [state, debouncedSetState]; };