Maximum update depth exceeded (effect sets state with no dependency array)
Locate the failed assumption, reproduce it, then repair the cause.
What actually caused it
useEffect with no second runs after every render that committed. If the effect calls a setState that changes state, React renders again, the effect runs again, and the cycle does not stop. The familiar message is “Maximum update depth exceeded.” A dependency that includes an or array created during render can cause the same loop, because that value is new every time even when the contents look the same.
The missing is not the same as an empty array. No array means every render. An empty array means mount and unmount only.
Minimal reproduction
Set state with no dependency array
useEffect(() => {
setCount(count + 1);
});Every commit schedules another commit.
The fix
Stop setting state unconditionally inside an effect. If the effect should run once, pass an empty dependency and do not set state in a way that retriggers it. If it should respond to a value, list that value and set state only when the next value is actually different.
For fetched data, keep the request in the effect, ignore stale responses in cleanup, and do not put the state you just set back into the dependency list unless a change to it should refetch. Confirm the network panel shows one request per real dependency change, not a stream of identical ones.
Run once on mount
useEffect(() => {
setCount(1);
}, []);The empty does not include count, so the effect does not re-run when count updates.