UNPKG

@coreui/vue-pro

Version:

UI Components Library for Vue.js

17 lines (13 loc) 418 B
import { ref } from 'vue' export const useDebouncedCallback = <F extends Function>(callback: F, delay: number) => { const timeout = ref<ReturnType<typeof setTimeout>>() const debouncedFn = (...args: any[]) => { const handler = () => { clearTimeout(timeout.value) callback(...args) } clearTimeout(timeout.value) timeout.value = setTimeout(handler, delay) } return debouncedFn() }