#Is there a separate effect method for respective signals? like in react, we can pass a variable

1 messages · Page 1 of 1 (latest)

coral ore
#

Everytime, any signal updates, the effect() method is called. How can I have a separate effect() for the signal that is triggered?

acoustic cove
#

effect will be invoked when one of the signals in its scope are updated.

#

not every signal.

#

if you need to unscope some signals you can do that with untracked

#
effect(() => {
 const myVal =  untracked(() => mySignal()) // not tracked
 const newVal = myVal + mySignal2() // tracked
})
coral ore
#

Thank you very much
RESOLVED

But is it a good approach though?

#

Suppose I have 3 signals
mySignal()
mySignal2()
mySignal3()

I want to perform some logic on mySignal() update trigger.

I want to perform some other logic on mySignal3() update trigger.

I would have to check in effect()

acoustic cove
#

Yes

#

The next question you need to ask yourself, do you really need an effect ? (or can it be a state derivation instead)