useDebounce
Expose a ref value only after it has stopped changing for the delay you choose.
Edit the code and the preview updates as you type.
What it does
A search field needs a reactive query for fetching, but the app should wait until the person pauses before using the latest value.
The playground is a small, runnable example. Change the code and try the interaction before copying it into an app.
The code
const query = ref('')
const settledQuery = useDebounce(query, 300)
// Watch settledQuery or pass it to a reactive data request.Where you'd use it
- Debouncing a search query ref
- Waiting for a settled filter value
- Reducing reactive work while a form field changes
In Nuxt (and other gotchas)
This returns a debounced ref, so it is convenient with reactive Nuxt data options. The browser is not required for the ref transform itself; when the value drives markup, ensure server output and the initial client value begin consistently.
When not to use it
Use useDebounceFn when you need to delay an action rather than a value. Use throttling when updates should continue at regular intervals during ongoing input.
Links
- Official useDebounce docs for every option and type
- Source code on GitHub