UNPKG

@fruits-chain/react-native-xiaoshu

Version:
31 lines (25 loc) 827 B
/** * 代码来源:https://github.com/alibaba/hooks/blob/master/packages/hooks/src/usePersistFn/index.ts * 关于 this:https://www.jianshu.com/p/8b3a2513d8e5 */ import { useRef } from 'react'; /** * 持久化 function 的 Hook */ function usePersistFn(fn) { const fnRef = useRef(fn); fnRef.current = fn; const persistFn = useRef(); if (!persistFn.current) { persistFn.current = function () { var _fnRef$current; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return (_fnRef$current = fnRef.current) === null || _fnRef$current === void 0 ? void 0 : _fnRef$current.apply(this, args); }; } return persistFn.current; } export default usePersistFn; //# sourceMappingURL=usePersistFn.js.map