UNPKG

@vue-widget/hooks

Version:

hooks from react to vue

16 lines (15 loc) 412 B
import { ref, watch } from "vue"; export function useMemo(getValue, condition, shouldUpdate) { var cacheRef = ref(getValue()); watch(condition, function (next, pre) { if (shouldUpdate) { if (shouldUpdate(next, pre)) { cacheRef.value = getValue(); } } else { cacheRef.value = getValue(); } }); return cacheRef; }