score:1

my question is should i ignore the warning and disable it or i am doing something wrong, if i am how can i correct it?

this is a subjective question but generally you should include all dependencies the linter complains about. there are exceptions to this though, for example, when wanting an effect to run only once when the component mounts. you can ofc omit any dependencies you like, if you really know what you are doing, but be aware that the linter will complain about missing dependencies or silently ignore them if you disable the linting rule for that line.

from what i see, mobile is a dependency and should be included.

useeffect(() => {
  if (!loading) {
    setdata({
      model: mobile.model,
      name: mobile.name,
      network: mobile.network,
      price: mobile.price,
      description: mobile.description,
    });
  }
}, [loading, mobile]);

i have a stateobject that i am changing in my useeffect. i only want it to work when loading changes.

the if (!loading) check ensures that setdata is only called when loading changes and evaluates true. including mobile in the dependency array ensures when setdata is called that it has the latest value.


Related Query

More Query from same tag