Skip to content

/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

bash
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

jsx
// 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

jsx
// 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