Function useDebouncedState

  • Returns stateful values and a function to update them. Upon invocation of setState, the nextState is assigned synchronously, and the component is re-rendered. After the ms the currState is set to nextState and component is re-rendered again.

    Type Parameters

    • S

      The type of stateful value.

    Parameters

    • ms: number

      The delay after which currState is synchronized with nextState.

    • initialState: S | (() => S)

      Thee initial state or a callback that returns an initial state.

    Returns DebouncedStateProtocol<S>

  • Returns stateful values and a function to update them. Upon invocation of setState, the nextState is assigned synchronously, and the component is re-rendered. After the ms the currState is set to nextState and component is re-rendered again.

    Type Parameters

    • S = undefined

      The type of stateful value.

    Parameters

    • ms: number

      The delay after which currState is synchronized with nextState.

    Returns DebouncedStateProtocol<S | undefined>