Dynamically remove effect
Is it possible to remove an effect created with createEffect()? Or is there a different way to think about dynamically adding and removing effects?
I am in the beginning stages of building a UI where the user can dynamically route signal flow + relationships between elements... still working on fully wrapping my head around reactivity, etc!
3 Replies
Maybe you should take a look at
untrack
to remove the effect of a signal or a derived signal:
https://www.solidjs.com/tutorial/reactivity_untrack
or you can use on
to only watch the depencies in your first argument.
https://docs.solidjs.com/reference/reactive-utilities/onSolidJS
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.
There is probably something triggering if the effect needs to be there or not. Note that in solidjs, the dependency tree from signal is fully dynamic, so assuming you have a signal
enableEffect
, you can do following
Note that for simple logic like that, it's obviously more readable that way, but example above is to illustrate nested effects
Ahh okay this is helpful!!!.... I am still wrapping my head around nested effects. I am going to try this way and see if it works for my use case.