@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
24 lines (22 loc) • 593 B
JavaScript
;
/**
* 代码来源: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 (...args) {
return fnRef.current?.apply(this, args);
};
}
return persistFn.current;
}
export default usePersistFn;
//# sourceMappingURL=usePersistFn.js.map