@taro-hooks/ahooks
Version:
22 lines (21 loc) • 672 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var tslib_1 = require("tslib");
var core_1 = require("@taro-hooks/core");
var shared_1 = require("@taro-hooks/shared");
var useThrottleFn_1 = tslib_1.__importDefault(require("../useThrottleFn"));
function useThrottle(value, options) {
var _ref = (0, core_1.useState)(value),
throttled = _ref[0],
setThrottled = _ref[1];
var throttleFn = (0, useThrottleFn_1["default"])(function () {
setThrottled(value);
}, options);
(0, core_1.useEffect)(function () {
(0, shared_1.escapeState)(throttleFn).run();
}, [value]);
return throttled;
}
exports["default"] = useThrottle;