@i-novus/ui-core
Version:
Базовые UI компоненты
18 lines (17 loc) • 536 B
JavaScript
import { useRef } from 'react';
const MEMO_KEY = Symbol('core-memoized');
export function useMemoFunction(cb) {
const fooRef = useRef(null);
if (cb === undefined) {
return undefined;
}
if (fooRef.current === null) {
fooRef.current = {
returnFunction: ((...args) => fooRef.current.bodyFunction(...args)),
bodyFunction: cb,
};
fooRef.current.returnFunction.memoProp = MEMO_KEY;
}
fooRef.current.bodyFunction = cb;
return fooRef.current.returnFunction;
}