UNPKG

rc-hooks

Version:
24 lines (23 loc) 788 B
/** * 用来处理节流函数的 Hook。 * * @param {Function} fn 需要节流的函数。 * @param {number} [wait=0] 节流等待时间,单位为毫秒。默认 `0`。 * @param {boolean} [immediate=true] 是否在延迟开始前调用。默认 `true`。 * @returns * @example * const [value, setValue] = useState(0); * // 频繁调用 run,但只会每隔 500ms 执行一次函数。 * const { run } = useThrottleFn(setValue, 500); */ declare function useThrottleFn<T extends (...args: any[]) => any>(fn: T, wait?: number, immediate?: boolean): { run: { (this: any, ...args: any[]): any; cancel: () => void; flush: () => any; pending: () => boolean; }; cancel: () => void; flush: () => any; }; export default useThrottleFn;