useThrottledFn

A React Hook that helps to create a debounced function.

Demo

Source
Count:
0
wait:
1000

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const throttledFn = useThrottledFn(fn, { wait: 1000 })

Fn

The function to throttle.

Options

export type ThrottleOptions = { /** * time frame for throttle * * @defaultValue 0 */ wait?: number /** * whether to invoke the function at the start of each period * * @defaultValue true */ leading?: boolean /** * whether to invoke the function at the end of each period * * @defaultValue true */ trailing?: boolean } export interface UseThrottledFnOptions extends ThrottleOptions {}

Returns

The debounced function, same as the input function.