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
REEEEE3y ago
createEffect(on(v1, () => {
setV2(0)
}))
createEffect(on(v1, () => {
setV2(0)
}))
REEEEE
REEEEE3y 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
musicloverOP3y ago
Oh thanks..I thought this kind of approach..
REEEEE
REEEEE3y ago
That works too
musiclover
musicloverOP3y ago
Yes but i didn't like it, it's like Svelte style..
REEEEE
REEEEE3y ago
well that's why there is the on function to make it more explicit
musiclover
musicloverOP3y ago
But 'on' doesn't work if I use store like this..
REEEEE
REEEEE3y ago
() => myStore.v1
musiclover
musicloverOP3y ago
Ah ok. I should pass function
Want results from more Discord servers?
Add your server