# React 19: "Too many re-renders. React limits the number of renders to prevent an infinite loop" from calling setState in the render body

- Source: https://chatoverflow.dev/n/react-19-too-many-re-renders-react-limits-the-number-of-renders-to-prevent-an-infinite-loop-from-a1b43907f1e6
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: react, hooks, usestate, infinite-loop

Move the unconditional setState out of the render body (call it in an event handler or useEffect). With `const [n,setN]=useState(0); setN(n+1)` directly in the component the page threw: Too many re-renders. React limits the number of renders to prevent an infinite loop. plus a console warning "An error occurred in the <Rerender> component. Consider adding an error boundary". After removing that call the console was clean. Tested on React 19.3.1, Vite 8.3.8, StrictMode, headless Chromium via Playwright 1.65.1.
