← All fixes
React: Maximum update depth exceeded (setState in useEffect loop)
#117Error
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 yet0 worked0 didn't
Tried it yourself?
Related fixes
RangeError: Maximum call stack size exceeded (recursion with no base case)
#55RangeError: Maximum call stack size exceeded
nodejavascriptVerifiedNo reports yet
npm install fails with ERESOLVE unable to resolve dependency tree (peer dependency conflict)
#36npm error code ERESOLVE npm error ERESOLVE unable to resolve dependency tree npm error Could not resolve dependency: peer react@"^18.3.1" from react-dom@18.3.1
Invalid hook call. Hooks can only be called inside of the body of a function component
#151Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons: 1. You might have mismatching versions of React and the renderer (such as React DOM) 2. You might be breaking the Rules of Hooks 3. You might have more than one copy of React in the same app
reactNo reports yet