UNPKG

@cran/lib.vue.ref

Version:

Vue Reactivity Extensions

20 lines (19 loc) 490 B
import { watch } from "vue"; /** * Always return value to a fallback after the * given delay (or on next stack) * @since 0.2.0 * @category Controller */ export function useAutoReset(ref, delay, fallback = ref.value) { let timer = null; return watch(ref, function onNext() { if (timer) { clearTimeout(timer); } timer = setTimeout(function onTimeout() { timer = null; ref.value = fallback; }, delay); }); }