amis-rpc-design/node_modules/rc-util/es/hooks/useMemo.js

9 lines
354 B
JavaScript
Raw Normal View History

2023-10-07 19:42:30 +08:00
import * as React from 'react';
export default function useMemo(getValue, condition, shouldUpdate) {
var cacheRef = React.useRef({});
if (!('value' in cacheRef.current) || shouldUpdate(cacheRef.current.condition, condition)) {
cacheRef.current.value = getValue();
cacheRef.current.condition = condition;
}
return cacheRef.current.value;
}