Skip to content

watchOnce

Category
Export Size
123 B
Last Changed
4 weeks ago

Shorthand for watching value with { once: true }. Once the callback fires once, the watcher will be stopped. See Vue's docs for full details.

Usage

Similar to watch, but with { once: true }

ts
import { 
watchOnce
} from '@vueuse/core'
watchOnce
(source, () => {
// triggers only once
console
.
log
('source changed!')
})

Type Declarations

ts
export declare function 
watchOnce
<
T
>(
source
:
WatchSource
<
T
>,
cb
:
WatchCallback
<
T
,
T
| undefined>,
options
?:
Omit
<
WatchOptions
<true>, "once">,
):
WatchHandle
export declare function
watchOnce
<
T
extends
Readonly
<
MultiWatchSources
>>(
source
: [...
T
],
cb
:
WatchCallback
<
MapSources
<
T
>,
MapOldSources
<
T
, true>>,
options
?:
Omit
<
WatchOptions
<true>, "once">,
):
WatchHandle
export declare function
watchOnce
<
T
extends object>(
source
:
T
,
cb
:
WatchCallback
<
T
,
T
| undefined>,
options
?:
Omit
<
WatchOptions
<true>, "once">,
):
WatchHandle

Source

SourceDocs

Contributors

Anthony Fu
Anthony Fu
Arthur Darkstone
山吹色御守
Kricsleo
Fernando Fernández
Howard Guo
Valery
vaakian X
lvjiaxuan
lvjiaxuan
HG
webfansplz

Changelog

Pending for release...
f1d32 - fix(shared): align overloads order of watch functions with original version (#5288)
b8102 - feat(watch): update watch return typo in watchExtractedObservable, watchDebounced, watchDeep, watchImmediate, watchOnce, watchThrottled and watchWithFilter (#4896)
00a72 - fix(types): update type casting for watch functions to use WatchSource (#4966)
08f7d - feat: use vue's native once behaviour (#4750)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
bb0a7 - feat: return function for manual watcher stopping (#3475)

Released under the MIT License.