Skip to content

useThrottle()

useThrottle<TArguments>(callback, delay): (...arguments_) => void

Defined in: src/hooks/state/useThrottle.ts:27

A custom React hook to throttle the execution of a callback function. Ensures the callback is only executed at most once every specified delay.

Type Parameters

TArguments extends unknown[]

Parameters

callback

(...arguments_) => void

The function to throttle.

delay

number

The delay in milliseconds between allowed executions of the callback.

Returns

Function

The throttled function.

Parameters

arguments_

...TArguments

Returns

void

Example

tsx
import { useThrottle } from '@zl-asica/react';

const MyComponent = () => {
  const handleClick = useThrottle(() => {
    console.log('Button clicked!');
  }, 1000);

  return <button onClick={handleClick}>Click me</button>;
};

Released under the MIT License.