import {useRef,} from 'react';
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 {
usePersistFn
}react usePersistFn
发布时间 2023-03-22 21:16:38作者: 袜子破了