useThrottle()
useThrottle<
TArguments>(callback,delay): (...arguments_) =>void
Defined in: src/hooks/state/useThrottle.ts:25
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
TArguments extends unknown[]
Parameters
callback
(...arguments_) => void
The function to throttle.
delay
number
The delay in milliseconds between allowed executions of the callback.
Returns
The throttled function.
(...
arguments_):void
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>;
};