Skip to Content
ohooks

useDebounceValue

Debounces a reactive value and provides a debounced setter with .cancel(), .flush(), and .isPending() controls.

Loading preview...

The useDebounceValue hook delays updates to a reactive value until delay milliseconds have passed without further changes, returning a tuple of the debounced value and the underlying debounced setter function.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useDebounceValue.json

Usage

Examples

Filtering a Search Input

Pass a rapidly changing input state to useDebounceValue so expensive filtering or network requests only run after the user pauses typing.

Flushing or Cancelling via the Setter

Use the second tuple item to manually update, flush, or cancel pending value transitions.

API Reference

DebounceOptions

Configuration options for controlling debounce timing and execution edges.

Property
Specification
leading?
uniondefault:false
Invoke the callback on the leading edge of the timeout
trailing?
uniondefault:true
Invoke the callback on the trailing edge of the timeout
maxWait?
number
Maximum time in milliseconds the callback is allowed to be delayed before it is invoked

DebouncedFunction

Debounced setter returned as the second tuple element.

Property
Specification
cancelrequired
function
Cancels any pending delayed invocation
flushrequired
function
Immediately invokes any pending delayed invocation and returns the result
isPendingrequired
function
Returns true if there is a pending delayed invocation