# Too many re-renders / useEffect infinite loop

> Canonical page (link this when citing): https://unbreakmyapp.vercel.app/fixes/useeffect-infinite-loop.html
> Category: Performance | Tools: Lovable, Bolt, v0, Cursor | Published: 2026-10-13 | Updated: 2026-10-13

## The error

Error: Too many re-renders. React limits the number of renders / Maximum update depth exceeded

## Why it happens

State is set during render, or a useEffect updates a value that's also in its dependency array (often an object or array recreated each render), so it loops forever and can hammer your API.

## How to fix it

1. Never call setState directly in the component body.
2. Check useEffect dependencies; avoid objects/arrays created inline.
3. Memoise with useMemo/useCallback or depend on primitive ids.
4. Move data fetching to React Query/SWR.

## Error codes this fixes

- `Too many re-renders / Maximum update depth exceeded` (React): https://unbreakmyapp.vercel.app/errors.html#too-many-re-renders-maximum-update-depth-exceeded

## Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

```text
My component throws 'Too many re-renders' or 'Maximum update depth exceeded' and spams API calls. Find setState calls during render and useEffect hooks whose dependencies change every render, fix them with correct dependency arrays, useMemo/useCallback or primitive dependencies, and explain each fix briefly.
```

## FAQ

### Can it cost me money?

Yes, looping fetches can burn API credits and database quota.

### Should I disable the lint rule?

No. The exhaustive-deps warning usually points at the bug.

## Sources (official documentation)

- [React: You Might Not Need an Effect](https://react.dev/learn/you-might-not-need-an-effect)
- [React: useEffect](https://react.dev/reference/react/useEffect)

## Related fixes

- [Postgres: too many connections / remaining connection slots are reserved](https://unbreakmyapp.vercel.app/fixes/supabase-too-many-connections.html)
- [App is slow: dozens of database calls per page (N+1 queries)](https://unbreakmyapp.vercel.app/fixes/slow-page-n-plus-one-queries.html)
- [Supabase query returns an empty array (no error)](https://unbreakmyapp.vercel.app/fixes/supabase-rls-empty-results.html)
- [new row violates row-level security policy for table](https://unbreakmyapp.vercel.app/fixes/supabase-rls-new-row-violates-policy.html)

---
Unbreak My App: free fixes for broken vibe-coded apps. https://unbreakmyapp.vercel.app/
