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/refDebounced.md
1---2category: Reactivity3alias: useDebounce, debouncedRef4---56# refDebounced78Debounce execution of a ref value.910## Usage1112```ts {5}13import { refDebounced } from '@vueuse/core'14import { shallowRef } from 'vue'1516const input = shallowRef('foo')17const debounced = refDebounced(input, 1000)1819input.value = 'bar'20console.log(debounced.value) // 'foo'2122await sleep(1100)2324console.log(debounced.value) // 'bar'25// ---cut-after---26function sleep(ms: number) {27return new Promise(resolve => setTimeout(resolve, ms))28}29```3031An example with object ref.3233```js34import { refDebounced } from '@vueuse/core'35import { shallowRef } from 'vue'3637const data = shallowRef({38name: 'foo',39age: 18,40})41const debounced = refDebounced(data, 1000)4243function update() {44data.value = {45...data.value,46name: 'bar',47}48}4950console.log(debounced.value) // { name: 'foo', age: 18 }51update()52await sleep(1100)5354console.log(debounced.value) // { name: 'bar', age: 18 }55```5657You can also pass an optional 3rd parameter including maxWait option. See `useDebounceFn` for details.5859## Recommended Reading6061- [**Debounce vs Throttle**: Definitive Visual Guide](https://kettanaito.com/blog/debounce-vs-throttle)6263## Type Declarations6465```ts66export type RefDebouncedReturn<T = any> = Readonly<Ref<T>>67/**68* Debounce updates of a ref.69*70* @return A new debounced ref.71*/72export declare function refDebounced<T>(73value: Ref<T>,74ms?: MaybeRefOrGetter<number>,75options?: DebounceFilterOptions,76): RefDebouncedReturn<T>77/** @deprecated use `refDebounced` instead */78export declare const debouncedRef: typeof refDebounced79/** @deprecated use `refDebounced` instead */80export declare const useDebounce: typeof refDebounced81```82