@td-design/rn-hooks
Version:
从ahooks里面抽取的一些在rn项目里可以使用的hooks。提高开发效率
26 lines (22 loc) • 677 B
JavaScript
;
var _tslib = require('../_virtual/_tslib.js');
var react = require('react');
var index = require('../useThrottleFn/index.js');
/**
* 用来处理节流值的 Hook。
* @param value 需要节流的值
* @param options 配置节流的行为
* @returns
*/
function useThrottle(value, options) {
var _a = _tslib.__read(react.useState(value), 2), throttled = _a[0], setThrottled = _a[1];
var run = index(function () {
setThrottled(value);
}, options).run;
react.useEffect(function () {
run();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value]);
return throttled;
}
module.exports = useThrottle;