Files
fuel-price/.agents/skills/vueuse-functions/references/refDebounced.md
Ovidiu U 4a3ce4cc1d
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
docs: add advanced skills for Vitest, Pinia, and Vue built-ins
Add comprehensive reference documentation for:
- Vitest: environments, projects/workspaces, type testing, vi utilities
- Pinia: HMR, Nuxt integration, SSR setup
- Vue: built-in components (Transition, Teleport, Suspense, KeepAlive) and advanced directives
2026-04-11 16:28:36 +01:00

82 lines
1.7 KiB
Markdown

---
category: Reactivity
alias: useDebounce, debouncedRef
---
# refDebounced
Debounce execution of a ref value.
## Usage
```ts {5}
import { refDebounced } from '@vueuse/core'
import { shallowRef } from 'vue'
const input = shallowRef('foo')
const debounced = refDebounced(input, 1000)
input.value = 'bar'
console.log(debounced.value) // 'foo'
await sleep(1100)
console.log(debounced.value) // 'bar'
// ---cut-after---
function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms))
}
```
An example with object ref.
```js
import { refDebounced } from '@vueuse/core'
import { shallowRef } from 'vue'
const data = shallowRef({
name: 'foo',
age: 18,
})
const debounced = refDebounced(data, 1000)
function update() {
data.value = {
...data.value,
name: 'bar',
}
}
console.log(debounced.value) // { name: 'foo', age: 18 }
update()
await sleep(1100)
console.log(debounced.value) // { name: 'bar', age: 18 }
```
You can also pass an optional 3rd parameter including maxWait option. See `useDebounceFn` for details.
## Recommended Reading
- [**Debounce vs Throttle**: Definitive Visual Guide](https://kettanaito.com/blog/debounce-vs-throttle)
## Type Declarations
```ts
export type RefDebouncedReturn<T = any> = Readonly<Ref<T>>
/**
* Debounce updates of a ref.
*
* @return A new debounced ref.
*/
export declare function refDebounced<T>(
value: Ref<T>,
ms?: MaybeRefOrGetter<number>,
options?: DebounceFilterOptions,
): RefDebouncedReturn<T>
/** @deprecated use `refDebounced` instead */
export declare const debouncedRef: typeof refDebounced
/** @deprecated use `refDebounced` instead */
export declare const useDebounce: typeof refDebounced
```