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 changed.
Optional
options: WatchOptions<T>additional options.
Watches a single reactive value and executes a callback whenever that value changes.
watchValue
works like this:selector
is a tracked function that shall return a value. This value is usually obtained by accessing one or more reactive objects.selector
changes,callback
will be executed with the new value (the old value is available as well). The body ofcallback
is not reactive.The values returned by the selector are compared using object identity by default (i.e.
Object.is
). Note that you can provide a customequal
function to change this behavior.Example:
watchValue
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: