UNPKG

@vue-widget/hooks

Version:

hooks from react to vue

20 lines (19 loc) 470 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useMemo = useMemo; var _vue = require("vue"); function useMemo(getValue, condition, shouldUpdate) { var cacheRef = (0, _vue.ref)(getValue()); (0, _vue.watch)(condition, function (next, pre) { if (shouldUpdate) { if (shouldUpdate(next, pre)) { cacheRef.value = getValue(); } } else { cacheRef.value = getValue(); } }); return cacheRef; }