React stops with 'Too many re-renders' as soon as a component loads
Too many re-renders. React limits the number of renders to prevent an infinite loop.Short answer
This error means a component sets state while it is rendering, every time it renders, so React stops the loop. The usual culprit is an event handler that is called instead of passed, like onClick={save()}. The other is a set call in the component body with no condition around it.
Fix it fast
1Find out which cause you have
Open the browser console, expand the error and read the stack. The first frame inside your own file names the line that calls a state setter during render.
# In the browser console: click the arrow next to the error, # then look for the first frame in your own component file. # To find suspicious handlers quickly: grep -rnE "on[A-Z][A-Za-z]*=\{[A-Za-z.]+\([^)]*\)\}" app components src2Match what you see, then jump to its fix
- 1
The stack ends in the component's return statement, and JSX contains onClick={handleClick()}An event handler is called during render instead of passedFix - 2
The stack points at a line like setCount(...) or dispatch(...) sitting directly inside the component function, outside any handler or EffectA state setter runs in the component body with no conditionFix
- 1
What does the error look like?
Too many re-renders. React limits the number of renders to prevent an infinite loop.
Cause 1 of 2
An event handler is called during render instead of passed
1Check
Look at every handler prop in the component. A pair of parentheses after the function name runs it while React builds the element, and if that function sets state, every render triggers another render.
grep -rnE "on(Click|Change|Submit)=\{[A-Za-z.]+\(" app components src2Fix
Pass the function itself, or wrap the call in an arrow function so it runs only when the event fires.
// wrong: runs during render
<button onClick={handleClick()}>Save</button>
// right: passes the handler
<button onClick={handleClick}>Save</button>
// right: inline function, also fine for passing arguments
<button onClick={() => handleClick(item.id)}>Save</button>3Verify
Reload the page. The component should render once and the console error should be gone; clicking the button should now run the handler.
npm run devConfirmed by react.dev
Cause 2 of 2
A state setter runs in the component body with no condition
1Check
Search the component body for set calls that are not inside an event handler. Each such call schedules a render, and the next render calls it again.
grep -nE "^\s*set[A-Z][A-Za-z]*\(" components/MyComponent.tsx2Fix
Move the call into an event handler or an Effect. If you really need to adjust state while rendering (for example, to track the previous value of a prop), guard it with a condition that becomes false after the first update.
const [prevCount, setPrevCount] = useState(count)
const [trend, setTrend] = useState(null)
if (prevCount !== count) {
setPrevCount(count)
setTrend(count > prevCount ? 'increasing' : 'decreasing')
}3Verify
Reload and watch the console. The page should render normally and the state should settle after the first update.
npm run devConfirmed by react.dev
How do I stop it coming back?
- Read handler props as a habit: a function name with no parentheses means pass it, with parentheses means run it now.
- Keep state updates inside handlers and Effects; treat the component body as a place that only calculates JSX.
- Turn on the react-hooks ESLint rules so conditional or misplaced hook usage is flagged in the editor.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
ESLint says an element in a list is missing its key prop
react/jsx-key
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
react-i18next shows the wrong plural form for a count, or prints the key instead of the text
t('item') prints the key item instead of a translated sentence
i18next picks a plural from the count option and looks for keys ending in _one, _other and so on.
4 causes, each with a fixWeb apps
useSession throws because there is no SessionProvider above it
[next-auth]: `useSession` must be wrapped in a <SessionProvider />
useSession reads the session from React Context, and SessionProvider is what creates that context.
3 causes, each with a fixWeb apps
next/link throws React.Children.only on its children
Error: React.Children.only expected to receive a single React element child.
React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fix