useThrottleFn
React hooks that throttle function.
Usage
import { useThrottleFn } from "@reactuses/core";
const Demo = () => {
const [value, setValue] = useState(0);
const { run } = useThrottleFn(() => {
setValue(value + 1);
}, 500);
return (
<div>
<p style={{ marginTop: 16 }}> Clicked count: {value} </p>
<button type="button" onClick={run}>
Click fast!
</button>
</div>
);
};
Example
Clicked count: 0
Type Declarations
/// <reference types="lodash" />
export default function useThrottleFn<T extends (...args: any) => any>(
fn: T,
wait?: number,
options?: ThrottleSettings
): {
run: DebouncedFunc<(...args_0: Parameters<T>) => ReturnType<T>>
cancel: () => void
flush: () => ReturnType<T> | undefined
}