import { onBeforeUnmount, ref } from 'vue';
import raf from '../../_util/raf';
export default function useDelay(callback) {
  const idRef = ref(0);
  const clearRef = () => {
    raf.cancel(idRef.value);
  };
  onBeforeUnmount(() => {
    clearRef();
  });
  const triggerFn = () => {
    clearRef();
    idRef.value = raf(callback);
  };
  return triggerFn;
}