UNPKG

@react-hookz/web

Version:

React hooks done right, for browser and SSR.

14 lines (13 loc) 566 B
import { useDebouncedCallback, useSafeState } from '..'; /** * Like `useSafeState` but its state setter is debounced. * * @param initialState Initial state to pass to underlying `useSafeState`. * @param delay Debounce delay. * @param maxWait Maximum amount of milliseconds that function can be delayed * before it's force execution. 0 means no max wait. */ export function useDebouncedState(initialState, delay, maxWait = 0) { const [state, setState] = useSafeState(initialState); return [state, useDebouncedCallback(setState, [], delay, maxWait)]; }