UNPKG

vue-hooks-plus

Version:
22 lines (21 loc) 523 B
import { watchEffect, unref } from "vue"; function useTimeout(fn, delay, options) { const immediate = options == null ? void 0 : options.immediate; if (immediate) { fn(); } watchEffect((onInvalidate) => { if (unref(delay) === void 0 || typeof unref(delay) !== "number" || unref(delay) < 0) return; const _deply = unref(delay); const timer = setTimeout(() => { fn(); }, _deply); onInvalidate(() => { clearInterval(timer); }); }); } export { useTimeout as default };