UNPKG

react-enhanced-debounce-hook

Version:

A tiny, dependency-free React hook library for debouncing values and state. Includes two ergonomic APIs so you can pick the pattern that fits your use-case:

20 lines (19 loc) 640 B
export type DebounceStateControls = { flush: () => void; cancel: () => void; }; /** * useDebounceState * Returns [value, setValue, debouncedValue, controls] * * - value: immediate value to bind to input * - setValue: setter (accepts value or functional updater). optional second arg `immediate` to update debouncedValue immediately * - debouncedValue: value that updates after delay ms of inactivity * - controls: { flush, cancel } */ export declare function useDebounceState<T>(initialValue: T, delay?: number): [ T, (updater: T | ((prev: T) => T), immediate?: boolean) => void, T, DebounceStateControls ];