How to subscribe a signal using createEffect?

I have a code like this. I want to change v2 value to 0 if v1 value get changed. How to make this using createEffect?
9 Replies
REEEEE
REEEEE2y ago
createEffect(on(v1, () => {
setV2(0)
}))
createEffect(on(v1, () => {
setV2(0)
}))
REEEEE
REEEEE2y ago
You can use the on function to subscribe to certain signals https://www.solidjs.com/docs/latest/api#on
SolidJS
Solid is a purely reactive library. It was designed from the ground up with a reactive core. It's influenced by reactive principles developed by previous libraries.
musiclover
musiclover2y ago
Oh thanks..I thought this kind of approach..
REEEEE
REEEEE2y ago
That works too
musiclover
musiclover2y ago
Yes but i didn't like it, it's like Svelte style..
REEEEE
REEEEE2y ago
well that's why there is the on function to make it more explicit
musiclover
musiclover2y ago
But 'on' doesn't work if I use store like this..
REEEEE
REEEEE2y ago
() => myStore.v1
musiclover
musiclover2y ago
Ah ok. I should pass function