S
SolidJS8mo ago
Ditto

What is the most idiomatic way of disabling an effect after a condition is met?

Is it possible to disable an effect after some condition is met or should I just use an early return?
const [value, setValue] = useSignal<number | undefined>();

createEffect(() => {
if (value() !== undefined) {
// do something with value() then disable this effect
}
})
const [value, setValue] = useSignal<number | undefined>();

createEffect(() => {
if (value() !== undefined) {
// do something with value() then disable this effect
}
})
4 Replies
jer3m01
jer3m018mo ago
Use an early return or if the signal should be used after mount, use onMount(() => {})
bigmistqke
bigmistqke8mo ago
early return is fine. there is https://docs.solidjs.com/reference/secondary-primitives/create-reaction too but i never used it myself
jer3m01
jer3m018mo ago
TIL thanks!
bigmistqke
bigmistqke8mo ago
ur welcome!
Want results from more Discord servers?
Add your server