Do watcher's created in composables need to have their unwatch function invoked? #7633
-
Just a general curiosity since the docs don't cover this use case specifically. According to https://vuejs.org/guide/essentials/watchers.html#stopping-a-watcher, a watcher created syncronously inside setup are bound to the component instance and will be automatically stopped when the component is unmounted, but is the same true if the watcher is created within a composable? For example: component.vue
composable.ts
Kind of assuming that as long as the watcher is not created asyncronously the same rules apply and yes the watcher will be stopped automatically. Just in the pursuit of a definitive clear answer. Thank you kindly |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
From running into this problem i suppose that it won't automatically unwatch the watchers that are created within a composable. That means that every time I wish there was a way to create a Something like the automatic unwatch of Can we replicate the watch mechanism for auto unwatch when the component is unmounted? |
Beta Was this translation helpful? Give feedback.
-
Yes, that's correct. It's as if the |
Beta Was this translation helpful? Give feedback.
Yes, that's correct. It's as if the
watch()
was invoked where you called your composable, so it gets destroyed automatically, no need to add anonUnmounted()