SolidJSS
SolidJSโ€ข3y agoโ€ข
4 replies
RATIU5

How can I skip the first effect run with createEffect?

I have a
createEffect
hook that runs when my signal does. Awesome. What I don't want, is for the effect to run when the initial signal value is set. I tried the following without success:

const [getVal, setVal] = createSignal("initial");

let firstEffectHasRun = false;
createEffect(() => {
  if (firstEffectHasRun) {
    console.log("Boom!");
  } else {
    firstEffectHasRun = true;
  }
});

I don't get why this doesn't work since firstEffectHasRun should be cached since it's used within the callback.
Was this page helpful?