diff --git a/src/api/reactivity-core.md b/src/api/reactivity-core.md index c3078ae180..e2e2910c4d 100644 --- a/src/api/reactivity-core.md +++ b/src/api/reactivity-core.md @@ -453,10 +453,34 @@ Watches one or more reactive data sources and invokes a callback function when t flush: 'post', onTrack(e) { debugger + }, + onTrigger(e) { + debugger } }) ``` + Stopping the watcher: + + ```js + const stop = watch(source, callback) + + // when the watcher is no longer needed: + stop() + ``` + + Side effect cleanup: + + ```js + watch(id, async (newId, oldId, onCleanup) => { + const { response, cancel } = doAsyncWork(newId) + // `cancel` will be called if `id` changes, cancelling + // the previous request if it hasn't completed yet + onCleanup(cancel) + data.value = await response + }) + ``` + - **See also**: - [Guide - Watchers](/guide/essentials/watchers.html)