a function that returns the value to watch.
a function that will be executed whenever the watched value changes.
Optionaloptions: 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.
Optionaloptions: WatchOptions<T>additional options.
Watches a single reactive value and executes a callback whenever that value changes.
watchValueworks like this:selectoris a tracked function that shall return a value. This value is usually obtained by accessing one or more reactive objects.selectorchanges,callbackwill be executed with the new value (the old value is available as well). The body ofcallbackis 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 customequalfunction to change this behavior.Example:
watchValuereturns 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: