@fruits-chain/react-native-xiaoshu
Version:
React Native UI library
40 lines (31 loc) • 986 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = require("react");
/**
* 代码来源:https://github.com/alibaba/hooks/blob/master/packages/hooks/src/usePersistFn/index.ts
* 关于 this:https://www.jianshu.com/p/8b3a2513d8e5
*/
/**
* 持久化 function 的 Hook
*/
function usePersistFn(fn) {
const fnRef = (0, _react.useRef)(fn);
fnRef.current = fn;
const persistFn = (0, _react.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;
}
var _default = usePersistFn;
exports.default = _default;
//# sourceMappingURL=usePersistFn.js.map