Back to Hooks

useThrottleFn

packages/hooks/src/useThrottleFn/index.zh-CN.md

3.9.71.3 KB
Original Source

useThrottleFn

用来处理函数节流的 Hook。

代码演示

基础用法

<code src="./demo/demo1.tsx" />

API

typescript
const {
  run,
  cancel,
  flush
} = useThrottleFn(
  fn: (...args: any[]) => any,
  options?: Options
);

Params

参数说明类型默认值
fn需要节流的函数(...args: any[]) => any-
options配置节流的行为Options-

Options

参数说明类型默认值
wait等待时间,单位为毫秒number1000
leading是否在延迟开始前调用函数booleantrue
trailing是否在延迟开始后调用函数booleantrue

Result

参数说明类型
run触发执行 fn,函数参数将会传递给 fn(...args: any[]) => any
cancel取消当前节流() => void
flush当前节流立即调用() => void