a function that returns the values to watch.
a function that will be executed whenever the watched values changed.
Optionaloptions: WatchOptions<Values> & { immediate?: false }additional options.
This overload is used when immediate is not set to false.
a function that returns the values to watch.
a function that will be executed whenever the watched values changed.
Optionaloptions: WatchOptions<Values>additional options.
Watches reactive values and executes a callback whenever those values change.
watchworks like this:selectoris a tracked function that shall return an array of values. Those values are usually obtained by accessing one or more reactive objects.selectorchange,callbackwill be executed with those values (the old values are available as well). The body ofcallbackis not reactive.The arrays returned by the selector are compared using shallow equality by default: the callback runs if the length of the array changes or if one of its entries has a different identity. Note that you can provide a custom
equalfunction to change this behavior.Example:
watchreturns 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: