Created
April 16, 2026 20:17
-
-
Save antlis/8baab6141f2bb785bb34da7bcc830d45 to your computer and use it in GitHub Desktop.
Reactive debounced ref for handling user input (search, filters) without excessive API calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function useDebouncedRef<T>(value: T, delay = 300) { | |
| const state = ref(value) | |
| const debounced = ref(value) | |
| let timer: any | |
| watch(state, (val) => { | |
| clearTimeout(timer) | |
| timer = setTimeout(() => { | |
| debounced.value = val | |
| }, delay) | |
| }) | |
| return { state, debounced } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case: