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

**Code:** `Too many re-renders` · **Category:** React · **Seen on:** React

A state update runs during render, which triggers another render, which updates state again — forever.

## Meaning

Calling `setState` unconditionally in the component body — or passing `onClick={setCount(1)}` instead of a function — makes every render schedule another one.

## Common causes

- `onClick={handle()}` instead of `onClick={handle}` or `onClick={() => handle()}`
- `setState` called directly in the component body
- useEffect without a dependency array that sets state
- useEffect dependency that changes every render (new object/array literal)

## Quick fix

1. Pass functions to event props, don’t call them
2. Move state updates into event handlers or effects with correct dependencies
3. Memoize object/array dependencies with useMemo

## Detailed fix by platform

### React

1. Common fix:

```jsx
<button onClick={setOpen(true)}>Open</button>          // ❌ runs during render
<button onClick={() => setOpen(true)}>Open</button>    // ✅
```


## How to diagnose

1. **Event props** — Any `onX={fn()}`?
2. **Render body** — Any unconditional setState?
3. **Effects** — Dependency arrays correct?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/react/too-many-re-renders)
