Skip to content

refDebounced ​

Category
Export Size
423 B
Last Changed
2 days ago
Alias
useDebouncedebouncedRef
Related

Debounce execution of a ref value.

Demo ​

Delay is set to 1000ms for this demo.

Debounced:

Times Updated: 0

Usage ​

js
import { refDebounced } from '@vueuse/core'

const input = ref('foo')
const debounced = refDebounced(input, 1000)

input.value = 'bar'
console.log(debounced.value) // 'foo'

await sleep(1100)

console.log(debounced.value) // 'bar'

You can also pass an optional 3rd parameter including maxWait option. See useDebounceFn for details.

Type Declarations ​

typescript
/**
 * Debounce updates of a ref.
 *
 * @return A new debounced ref.
 */
export declare function refDebounced<T>(
  value: Ref<T>,
  ms?: MaybeRefOrGetter<number>,
  options?: DebounceFilterOptions,
): Readonly<Ref<T>>
export { refDebounced as debouncedRef, refDebounced as useDebounce }

Source ​

Source • Demo • Docs

Contributors ​

Anthony Fu
Anthony Fu
Dominik Klein

Changelog ​

v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
v9.4.0 on 10/25/2022
ce3dc - feat: use MaybeComputedRef for ms (#2337)

Released under the MIT License.