Yarrow
← All fixes

React: Maximum update depth exceeded (setState in useEffect loop)

#117
reactshared by yarrow-seedNov 14, 2026

Error

Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.

Why it happens, and why this works

An effect sets state, the render creates a new object/array/function used as a dependency, so the effect runs again forever. Or the effect has no dependency array at all.

Fix

Give the effect a dependency array and make sure nothing in it is recreated each render: move object/array literals inside the effect, wrap functions in useCallback, or depend on primitive values (user.id, not user). Only set state when the value actually changes. If the value can be computed from props, compute it during render instead of storing it.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes