Too Many Re-renders in React
Infinite Render Loop Complete Solution
React 19 • Next.js 15 • TypeScript • Vite • React Router • Redux Toolkit
🌀 What Is the “Too Many Re-renders” Error?
The “Too many re-renders” error is one of the most common and frustrating issues in React development. It occurs when React detects that a component is re-rendering too many times in a loop, exceeding the built-in limit of 50 renders (in development) to prevent the browser from crashing.
The full error message reads:
Too many re-renders. React limits the number of renders to prevent an infinite loop.
In this guide, we break down every possible cause and give you step-by-step fixes tailored for React 19, Next.js 15, TypeScript, Vite, React Router, and Redux Toolkit.
⚡ Quick Reference — Common Causes at a Glance
setState directly inside the component's render logic triggers an infinite loop.useEffect updates state without a dependency array, causing endless re-renders.🧩 Detailed Breakdown — Every Cause Solved
Each card below dives deep into one specific cause of the "Too many re-renders" error, with root causes, code examples, and step-by-step fixes.
🛡️ Prevention — Avoid Infinite Loops Altogether
State updates should only happen in event handlers,
useEffect, or callbacks.
If you need derived data, use useMemo instead.
Always pass a dependency array to
useEffect. If you need to run an effect
only once, use []. If you need to update based on props/state, list them.
Wrap functions passed to child components with
useCallback to prevent
unnecessary re-renders and loops.
Compute derived data with
useMemo instead of calculating it in the render body,
especially if it triggers state changes.
Only dispatch actions in event handlers or effects — never in render. Use selectors with
useSelector to avoid unnecessary re-renders.
❓ Frequently Asked Questions
In development mode, React limits renders to 50 before throwing the "Too many re-renders" error. In production, the limit is higher (usually 150) but the error can still occur and freeze the app.
The limit exists to prevent infinite loops from crashing the browser. If you hit this limit, it's a clear sign that you have a logic error in your component.
Yes. While the development limit is 50, production builds also have a limit (around 150). If your loop is fast enough, you'll still hit the limit and the error will appear in the console, potentially freezing your app.
No. The render limit remains unchanged in React 19.
React's concurrent features (like useTransition) can help
with performance but don't prevent infinite loops — they'll still trigger
the error if you have a logic bug.
Best practices for debugging:
- Add console logs — log the component name and count to see how often it renders.
- Use React DevTools — the "Profiler" tab can show render frequency.
- Check useEffect dependencies — missing or incorrect dependencies are the #1 cause.
- Look for setState in render — search for
setStateordispatchcalls outside of event handlers. - Use the React DevTools "Highlight updates" — visually see which components are re-rendering.
Yes. Common Redux-related causes include:
- Dispatching actions directly in the render body.
- Using
useSelectorwith a selector that returns a new object every time. - Using
useDispatchinsideuseEffectwithout proper dependencies.
Fix: Use shallowEqual from react-redux
or memoize selectors with reselect or createSelector.
// ✅ Use memoized selectors
import { createSelector } from '@reduxjs/toolkit';
const selectUser = createSelector(
state => state.user,
user => user
);

0 Comments
thanks for your comments!