Skip to main content
Next.js & React · Developer Error Resolution Lab

Fix React Error: 'Too many re-renders. React limits the number of renders to prevent an infinite loop'

Prevent infinite re-render loops caused by immediately invoking setState functions inside JSX render bodies.

Triggered Error Message:

Error: Too many re-renders. React limits the number of renders to prevent an infinite loop.

Customize Solution for Your Environment
// Always wrap handlers in an arrow function:
// ❌ WRONG: onClick={setActiveTab(true)}
// ✅ CORRECT:
<button onClick={() => setActiveTab(true)}>
  Activate
</button>

Root Cause & Mechanism Analysis

Why does this error occur?

Calling `setState()` directly inside the component body or passing `onClick={handleClick()}` (calling the function immediately upon render rather than passing a callback reference).

Frequently Asked Questions

Can useEffect trigger this error?
Yes! If a `useEffect` updates state `A`, and state `A` is listed in the effect's dependency array without an exit condition, an infinite loop occurs.
Browse All 35 Guides