Skip to content

useThrottleFn

描述

用来处理函数节流的 Hook。

示例

ts
import { useThrottleFn } from '@base-web-kits/base-tools-react';
import React, { useState } from 'react';

export default () => {
  const [value, setValue] = useState(0);
  const { run } = useThrottleFn(
    () => {
      setValue(value + 1);
    },
    { wait: 500 },
  );

  return (
    <div>
      <p style={{ marginTop: 16 }}> Clicked count: {value} </p>
      <button type="button" onClick={run}>
        Click fast!
      </button>
    </div>
  );
};

来源

ahooks