mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-16 01:41:15 +08:00
17 lines
367 B
TypeScript
17 lines
367 B
TypeScript
import { Ref, ref, watch } from 'vue';
|
|
|
|
export default function useMemo<T>(
|
|
getValue: () => T,
|
|
condition: any[],
|
|
shouldUpdate: (prev: any[], next: any[]) => boolean,
|
|
) {
|
|
const cacheRef: Ref<T> = ref(getValue() as any);
|
|
watch(condition, (pre, next) => {
|
|
if (shouldUpdate(pre, next)) {
|
|
cacheRef.value = getValue();
|
|
}
|
|
});
|
|
|
|
return cacheRef;
|
|
}
|