a function that returns the value to watch.
a function that will be executed whenever the watched value changes.
Optional
options: WatchOptions<T> & { immediate?: false }additional options.
This overload is used when immediate
is not set to false
.
a function that returns the value to watch.
a function that will be executed whenever the watched value changes.
Optional
options: WatchOptions<T>additional options.
Watches a single reactive value and executes a callback whenever that value changes.
This function is the synchronous variant of watchValue. It will re-execute after every fine grained change, even if those changes occur in immediate succession.
syncWatchValue
should therefore be considered a low level primitive, for most use cases watchValue should be the right tool instead.Example:
syncWatchValue
returns a handle that can be used to unsubscribe from changes. That handle'sdestroy()
function should be called to stop watching when you are no longer interested in updates: