import {Ref, unref, watch, isRef} from 'vue'; import {sources, useEffect, useRef} from './index'; const useInterval = (callback: Function | Ref, delay?: number | Ref) => { const savedCallback = useRef(unref(callback)); if (isRef(callback)) { watch(callback, () => { savedCallback.value = unref(callback); }); } useEffect(() => { if (unref(delay) !== null) { const interval = setInterval(unref(savedCallback), unref(delay) || 0); return () => clearInterval(interval); } return undefined; }, sources(delay)); }; export default useInterval;