An open API service indexing awesome lists of open source software.

https://github.com/vue-reactivity/watch

The missing `watch` for @vue/reactivity
https://github.com/vue-reactivity/watch

vue-reactivity vue3 watch

Last synced: 8 months ago
JSON representation

The missing `watch` for @vue/reactivity

Awesome Lists containing this project

README

          




The (missing) watch for @vue/reactivity. Works without Vue.


npm
npm bundle size


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