S
SolidJS3mo ago
RATIU5

How do I run an effect every change except initialization?

I need to run an effect every subsequent change of a signal's value. I just need to skip the first initialization of the signal. I found this answer https://stackoverflow.com/a/78283918 and I implemented it, but it's not triggering on any updates.
const [value, setValue] = createSignal(props.defaultValue ?? 0);
createEffect(
on(
value,
(val) => {
console.log(val); // Should log when the value changes, but not on initialization
},
{ defer: true },
),
);
const [value, setValue] = createSignal(props.defaultValue ?? 0);
createEffect(
on(
value,
(val) => {
console.log(val); // Should log when the value changes, but not on initialization
},
{ defer: true },
),
);
4 Replies
mdynnl
mdynnl3mo ago
this should work if not try reproducing on the playground
RATIU5
RATIU5OP3mo ago
Hmmm. Can't seem to reporduce in the playground. Let me check my code again
Eve
Eve3mo ago
yeah, you're doing something wrong somewhere, because that absolutely works.
RATIU5
RATIU5OP3mo ago
You're right; my signal isn't updating elsewhere in my code. Considering this thread as solved.
Want results from more Discord servers?
Add your server