▲ 0 r/reactjs
how to use useEffect to update a state without being warned "missing dependency"
useEffect(() => {
setCounter(counter + 1)
}, [someState, someOtherState])
Im trying to do something where i want a state (lets say counter) to update when some other states update. and react-hooks/exhaustive-deps is warning me that i have to put "counter" in the dependency array or remove it entirely.
To be clear the code works as intended but the warning tells me that I'm probably not doing something right. I can't put counter in the dependency directly though because I would get a infinite loop. how can I make this work?
u/porca_b — 22 hours ago