UNPKG

@datametria/vue-components

Version:

DATAMETRIA Vue.js 3 Component Library with Multi-Brand Theming - 51 components + 10 composables with theming support, WCAG 2.2 AA, dark mode, responsive system

17 lines (12 loc) 428 B
import { ref, watch, type Ref } from 'vue' export function useDebounce<T>(value: Ref<T>, delay: number = 300): Ref<T> { const debouncedValue = ref<T>(value.value) as Ref<T> let timeout: ReturnType<typeof setTimeout> | null = null watch(value, (newValue) => { if (timeout) clearTimeout(timeout) timeout = setTimeout(() => { debouncedValue.value = newValue }, delay) }) return debouncedValue }