import type { Ref, WatchSource } from 'vue'; import { ref, watch } from 'vue'; export default function useMemo( getValue: () => T, condition: (WatchSource | object)[], shouldUpdate?: (prev: any[], next: any[]) => boolean, ) { const cacheRef: Ref = ref(getValue() as any); watch(condition, (next, pre) => { if (shouldUpdate) { if (shouldUpdate(next, pre)) { cacheRef.value = getValue(); } } else { cacheRef.value = getValue(); } }); return cacheRef; }