/errors/react/too-many-re-renders
Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated 2026-10-20
- tool
- React
- exit code
- 1
- versions
- React 16.8 – 19
- os
- any
React throws Too many re-renders. React limits the number of renders to prevent an infinite loop. when a component updates its own state while rendering: the update triggers another render, which updates state again, and so on. The most common cause is calling a setter in JSX, onClick={setCount(count + 1)}, instead of passing a function.
Reproduce the error
npm init -y >/dev/null
npm install --silent --no-audit --no-fund react@19 react-dom@19 >/dev/null 2>&1
node -e '
const React = require("react");
const { renderToString } = require("react-dom/server");
function Counter() {
const [count, setCount] = React.useState(0);
setCount(count + 1); // state update during render
return React.createElement("p", null, count);
}
try { renderToString(React.createElement(Counter)); } catch (e) { console.log(e.message); }'Output
Too many re-renders. React limits the number of renders to prevent an infinite loop.
Fix: pass a function, do not call it
// wrong: setCount runs during render
<button onClick={setCount(count + 1)}>+</button>
// right: React calls the function when the button is clicked
<button onClick={() => setCount(count + 1)}>+</button>Fix: compute instead of storing
// wrong: setting state from props during render
const [full, setFull] = useState('');
setFull(`${first} ${last}`);
// right: derive it
const full = `${first} ${last}`;If an update must run after render (for example syncing with something outside React), put it in useEffect with the right dependency list, and make sure the effect does not set a value that changes its own dependencies on every run.
Sources
Related pages
errors · reactEach child in a list should have a unique "key" propReact warns Each child in a list should have a unique "key" prop when map() returns elements without key. Use a stable id from your data, not the index.errors · nextjsHydration failed because the server rendered HTML didn't match the clientNext.js and React 19 report Hydration failed when server HTML differs from the first client render: Date.now(), window checks, locale formats, bad nesting.glossary · reactWhat is hydration in React and Next.js?Hydration is when React attaches event handlers and state to HTML rendered on the server, making a server-rendered page interactive without rebuilding it.