https://github.com/vue-reactivity/watch
The missing `watch` for @vue/reactivity
https://github.com/vue-reactivity/watch
vue-reactivity vue3 watch
Last synced: 6 months ago
JSON representation
The missing `watch` for @vue/reactivity
- Host: GitHub
- URL: https://github.com/vue-reactivity/watch
- Owner: vue-reactivity
- License: mit
- Created: 2020-09-17T20:17:29.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-06-01T16:28:26.000Z (about 4 years ago)
- Last Synced: 2025-08-16T22:26:21.864Z (11 months ago)
- Topics: vue-reactivity, vue3, watch
- Language: TypeScript
- Homepage:
- Size: 141 KB
- Stars: 125
- Watchers: 6
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
The (missing) watch for @vue/reactivity. Works without Vue.
want to know how it works or write one on your own? Check out this blog post
## Install
npm i @vue-reactivity/watch
### Usage
> Note: since there is no Vue instance to be bond, `watch` will **NOT** be auto disposed. You need to always **explicitly** call the returning function to stop it. Or you can try [@vue-reactivity/scope](https://github.com/vue-reactivity/scope) which will auto collect the effects for you.
Just like what you do in Vue.
```ts
import { ref, reactive, computed } from '@vue/reactivity'
import { watch, watchEffect } from '@vue-reactivity/watch'
const count = ref(1)
const stopWatch = watch(
count,
(newValue) => {
console.log(`Count: ${newValue}`)
}
)
count.value += 1
// Count: 2
stopWatch()
```
## License
MIT