function useDebouncedState<TValue, TSelected>(
initialValue,
options,
selector?): [TValue, SetValue<TValue>, OctaneDebouncer<SetValue<TValue>, TSelected>];Defined in: debouncer/useDebouncedState.ts:39
Creates debounced state with a scheduled setter.
With the default trailing behavior, each call restarts the wait timer and only the latest pending update executes. Leading and trailing options control the edges.
Returns [value, setValue, utility]. Read the value during component rendering. Setters accept a value or a functional updater. Updaters run when the utility executes, using the last committed value. Pending updates may be replaced or rejected according to the utility's scheduling rules. To store a function itself, pass an updater that returns that function.
The value updates independently of the utility selector. The default utility selection is {}. Pass a selector to subscribe to fields such as executionCount, isPending, or status where the underlying utility exposes them.
Call during component rendering. The hook retains its utility across renders and runs cleanup when the component unmounts. Options accept an object with top-level getters or an options factory. Function-valued core options remain callbacks. Local options override provider defaults without replacing the utility or its pending work. onUnmount replaces default cleanup and receives the utility instance. A custom callback must perform every needed cancel, stop, or abort action.
TValue
TSelected = { }
TValue
OctanePacerOptions<OctaneDebouncerOptions<SetValue<TValue>, TSelected>>
(state) => TSelected
[TValue, SetValue<TValue>, OctaneDebouncer<SetValue<TValue>, TSelected>]
import { useDebouncedState } from '@tanstack/octane-pacer'
// During component rendering:
const [count, setCount, utility] = useDebouncedState(0, { wait: 500 },
(state) => ({ executionCount: state.executionCount }),
)
setCount((previous) => previous + 1)
// Bind count and utility.state in the component. Read count for the committed value.useDebouncer