Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/watchDebounced.md
1---2category: Watch3alias: debouncedWatch4---56# watchDebounced78Debounced watch. The callback will only be invoked after the source stops changing for the specified duration.910## Usage1112Similar to `watch`, but offering extra options `debounce` and `maxWait` which will be applied to the callback function.1314```ts15import { watchDebounced } from '@vueuse/core'1617watchDebounced(18source,19() => { console.log('changed!') },20{ debounce: 500, maxWait: 1000 },21)22```2324### Options2526| Option | Type | Default | Description |27| ---------- | -------------------------- | ------- | ------------------------------------------ |28| `debounce` | `MaybeRefOrGetter<number>` | `0` | Debounce delay in ms (can be reactive) |29| `maxWait` | `MaybeRefOrGetter<number>` | — | Maximum wait time before forced invocation |3031All standard `watch` options (`deep`, `immediate`, `flush`, etc.) are also supported.3233### Reactive Debounce Time3435The debounce time can be reactive:3637```ts38import { watchDebounced } from '@vueuse/core'3940const debounceMs = ref(500)4142watchDebounced(43source,44() => { console.log('changed!') },45{ debounce: debounceMs },46)4748// Later, change the debounce time49debounceMs.value = 100050```5152## How It Works5354It's essentially a shorthand for the following code:5556```ts57import { debounceFilter, watchWithFilter } from '@vueuse/core'5859watchWithFilter(60source,61() => { console.log('changed!') },62{63eventFilter: debounceFilter(500, { maxWait: 1000 }),64},65)66```6768## Type Declarations6970```ts71export interface WatchDebouncedOptions<Immediate>72extends WatchOptions<Immediate>, DebounceFilterOptions {73debounce?: MaybeRefOrGetter<number>74}75export declare function watchDebounced<76T extends Readonly<MultiWatchSources>,77Immediate extends Readonly<boolean> = false,78>(79sources: [...T],80cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,81options?: WatchDebouncedOptions<Immediate>,82): WatchHandle83export declare function watchDebounced<84T,85Immediate extends Readonly<boolean> = false,86>(87source: WatchSource<T>,88cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,89options?: WatchDebouncedOptions<Immediate>,90): WatchHandle91export declare function watchDebounced<92T extends object,93Immediate extends Readonly<boolean> = false,94>(95source: T,96cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,97options?: WatchDebouncedOptions<Immediate>,98): WatchHandle99/** @deprecated use `watchDebounced` instead */100export declare const debouncedWatch: typeof watchDebounced101```102