Files
NapCatQQ/.pnpm-store/v3/files/de/3c07e7f8bd5429ab3e0d73a330df3eeeb76e1b1e0c578d86912fd00dea048670df01351bc6ff732ca115e34e40f454a861d89da304f5ae450ae69db5ef5a90
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

36 lines
1.2 KiB
Plaintext

import { __read, __spreadArray } from "tslib";
import throttle from 'lodash/throttle';
import { useMemo } from 'react';
import useLatest from '../useLatest';
import useUnmount from '../useUnmount';
import { isFunction } from '../utils';
import isDev from '../utils/isDev';
function useThrottleFn(fn, options) {
var _a;
if (isDev) {
if (!isFunction(fn)) {
console.error("useThrottleFn expected parameter is a function, got ".concat(typeof fn));
}
}
var fnRef = useLatest(fn);
var wait = (_a = options === null || options === void 0 ? void 0 : options.wait) !== null && _a !== void 0 ? _a : 1000;
var throttled = useMemo(function () {
return throttle(function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return fnRef.current.apply(fnRef, __spreadArray([], __read(args), false));
}, wait, options);
}, []);
useUnmount(function () {
throttled.cancel();
});
return {
run: throttled,
cancel: throttled.cancel,
flush: throttled.flush,
};
}
export default useThrottleFn;