I’m looking for recommendations about how to solve the following problem:
I have a component A that has two states, state1 and state2.
If I want to run an effect only when state1 changes but in the useEFfect callback I use the value of state2, how can I solve the issue about array dependencies eslint react hooks warning ?
Ex.
function A() {
const [state1, setState1] = useState(0);
const [state2, setState2] = useState(0);
useEffect(() => {
const a = state1 + state2;
// do some async logic using a
}, [state1]); //Here eslint react hooks rule requests adding state2 to the dependency array!
return <div> some text </div>
}