UNPKG

vue-hooks-plus

Version:
16 lines (15 loc) 444 B
"use strict"; const vue = require("vue"); const defaultShouldUpdate = (a, b) => !Object.is(a, b); function usePrevious(state, shouldUpdate = defaultShouldUpdate) { const prevRef = vue.ref(); const curRef = vue.ref(); vue.watchEffect(() => { if (shouldUpdate(curRef.value, state.value)) { prevRef.value = curRef.value; curRef.value = state.value; } }); return vue.readonly(prevRef); } module.exports = usePrevious;