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