S
SolidJS2mo 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
jer3m012mo ago
Use an early return or if the signal should be used after mount, use onMount(() => {})
bigmistqke
bigmistqke2mo ago
early return is fine. there is https://docs.solidjs.com/reference/secondary-primitives/create-reaction too but i never used it myself
jer3m01
jer3m012mo ago
TIL thanks!
bigmistqke
bigmistqke2mo ago
ur welcome!