Skip to content
On this page

watchOnce

Category
Export Size
187 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!')
})
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>
): void
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>
): void
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>
): void
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>
): void

Source

SourceDocs

Contributors

Anthony Fu
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

Changelog

v8.7.0 on 6/16/2022
bb0ac - fix(watch*): fix T type for WatchCallback (#1692)
v7.5.5 on 1/25/2022
b61ce - fix: watchOnce when called with immediate flag (#1180)

Released under the MIT License.