Ignore initial run of effect()

84 Views Asked by At

we have:

effect(() => {
  console.log(`Value is ${newValue()}`);
});

We don't want whole console.log to run on initial signal set. We want it to run only starting with 2nd change of the signal.

Should we have a private field initialRun (true initially) in our component and set it to false at the end of our effect() code so that each subsequent run actually executes !initialRun && console.log(....)?

Or is there any smarter way?

0

There are 0 best solutions below