UNPKG

@td-design/rn-hooks

Version:

从ahooks里面抽取的一些在rn项目里可以使用的hooks。提高开发效率

24 lines (21 loc) 677 B
import { __read } from '../_virtual/_tslib.js'; import { useState, useEffect } from 'react'; import useThrottleFn from '../useThrottleFn/index.js'; /** * 用来处理节流值的 Hook。 * @param value 需要节流的值 * @param options 配置节流的行为 * @returns */ function useThrottle(value, options) { var _a = __read(useState(value), 2), throttled = _a[0], setThrottled = _a[1]; var run = useThrottleFn(function () { setThrottled(value); }, options).run; useEffect(function () { run(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [value]); return throttled; } export { useThrottle as default };