Skip to content

watchOnce ​

Category
Export Size
107 B
Last Changed
5 months ago

watch that only triggers once.

Usage ​

After the callback function has been triggered once, the watch will be stopped automatically.

ts
import { watchOnce } from '@vueuse/core'

watchOnce(source, () => {
  // triggers only once
  console.log('source changed!')
})

Type Declarations ​

typescript
export declare function watchOnce<
  T extends Readonly<WatchSource<unknown>[]>,
  Immediate extends Readonly<boolean> = false,
>(
  source: [...T],
  cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
  options?: WatchOptions<Immediate>,
): WatchStopHandle
export declare function watchOnce<
  T,
  Immediate extends Readonly<boolean> = false,
>(
  sources: WatchSource<T>,
  cb: WatchCallback<T, Immediate extends true ? T | undefined : T>,
  options?: WatchOptions<Immediate>,
): WatchStopHandle

Source ​

Source • Docs

Contributors ​

Anthony Fu
Valery
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

Changelog ​

v10.6.0 on 11/9/2023
bb0a7 - feat: return function for manual watcher stopping (#3475)

Released under the MIT License.