The missing watch for @vue/reactivity
. Works without Vue.
want to write one on your own? Check out this blog post
npm i @vue-reactivity/watch
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.
Just like what you do in Vue.
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()
MIT