useDebouncedFn

A React Hook that create a debounced function.

Demo

Source
Count:
0
wait:
300

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const debouncedFn = useDebouncedFn(fn, options)

Fn

The function to debounce.

Options

export type DebounceOptions = { /** * Time to wait before invoking the function * * @defaultValue 0 */ wait?: number /** * immediately invoke before the timeout * * @defaultValue false */ leading?: boolean /** * invoke the function after the timeout * * @defaultValue true */ trailing?: boolean } export type UseDebouncedFnOptions = DebounceOptions & {}

Returns

A debounced verison of the function, same as the input function in type.