Error library / this error
How to fix it
Error: Maximum update depth exceeded.
What it means
A component keeps updating its own state in a loop, and React stopped it after too many rounds.
Common causes
- setState is called directly during render.
- An effect sets state that is in its own dependency list.
- An event handler is called immediately: onClick={doThing()} instead of onClick={doThing}.
- A dependency is a new object or array on every render.
How to fix it
1. Pass the function, do not call it
<button onClick={() => setOpen(true)}>Open</button>
2. Fix the effect dependencies
Set state only when something actually changed, and keep dependencies stable.
useEffect(() => {
setTotal(items.reduce((s, i) => s + i.price, 0));
}, [items]); // not [items, total]
3. Stabilize objects
Use useMemo or move constants outside the component so they are not new on every render.
Catch it the moment it happens
ErrorBell shows a dot on the page when this error occurs and takes you to the failing line, so you do not have to hunt through the console. Add it to Chrome, it is free.