Too many re-renders in React: why it happens and how to fix it

BeginnerReact interview questionBy , updated 3 December 2026

Short answer

Too many re-renders. React limits the number of renders to prevent an infinite loop. means a component sets state while it is rendering, every time, so each render schedules another one. The most common cause is calling an event handler instead of passing it, as in onClick={handleClick()}. Fix it by passing the function, moving the update into an event handler, or calculating the value during render instead of storing it.

What the error means

Rendering is supposed to be a pure calculation: props and state in, JSX out. React does allow a component to call its own state setter during render, for rare cases. When that happens, React throws away the JSX it just got and renders the same component again straight away.

If the setter is called on every render without a condition, that retry never ends. React counts the retries, and after a fixed limit (25 in React's current source) it gives up and throws this error. It is a real thrown error, not a console warning. It shows up in production too, as minified React error #301, and an error boundary can catch it.

The loop happens inside a single render, before anything reaches the screen. That is the difference from Maximum update depth exceeded, which comes from updates in effects and lifecycle methods after a commit.

Cause 1: calling a handler instead of passing it

// Wrong: handleClick runs during render and sets state
<button onClick={handleClick()}>Save</button>

// Right: pass the function
<button onClick={handleClick}>Save</button>

JavaScript inside JSX curly braces runs immediately. The () calls handleClick while React is rendering, handleClick calls a setter, and the loop starts. The React docs list this as the usual cause.

Cause 2: a setter with an argument

// Wrong: setOpen(true) runs during render
<button onClick={setOpen(true)}>Open</button>

// Right: wrap it in a function
<button onClick={() => setOpen(true)}>Open</button>

This is the same mistake in a form that is easy to miss. Whenever a handler needs an argument, wrap the call in an arrow function.

Cause 3: setting state in the component body

function Cart({ items }) {
  const [total, setTotal] = useState(0);
  setTotal(items.reduce((sum, i) => sum + i.price, 0)); // runs on every render
  return <p>Total: {total}</p>;
}

The fix is to stop storing a value you can calculate:

function Cart({ items }) {
  const total = items.reduce((sum, i) => sum + i.price, 0);
  return <p>Total: {total}</p>;
}

If the calculation is slow, wrap it in useMemo. Do not move it into an effect just to silence the error. That trades this error for an extra render on every change, and sometimes for a different loop.

Cause 4: adjusting state from props without a guard

Sometimes you really do need to reset some state when a prop changes. The React docs show a pattern for that, and the condition is what keeps it from looping:

function List({ items }) {
  const [selection, setSelection] = useState(null);
  const [prevItems, setPrevItems] = useState(items);

  if (items !== prevItems) {
    setPrevItems(items);
    setSelection(null);
  }
  // ...
}

Without the if, this is Cause 3 again. Even with it, the docs suggest first trying a key to reset the whole component, or storing an id and deriving the selected item. Implement usePrevious() without causing an additional render practises the same idea.

How to find the call that loops

Open the error in the browser console and expand the stack trace. The React docs recommend looking for the specific set function call in that stack. The component named in the trace is the one rendering. Then search that component for:

  • onSomething={fn( with parentheses right after the name.
  • A set...( call at the top level of the function body, outside any handler or effect.
  • A custom hook called from that component that sets state while it runs.

Common follow-up questions

Can useEffect cause "Too many re-renders"?

Not usually. An effect runs after the commit, so a looping effect produces the Maximum update depth exceeded message instead, or simply keeps re-rendering. This error points to code that runs during render.

Does Strict Mode cause this error?

No. Strict Mode calls your component twice in development to find impure code, but it does not loop. If you see the error only in Strict Mode, the bug is still a state update during render.

Can I raise the limit?

No, and you would not want to. The limit only stops a loop that would otherwise freeze the tab. Remove the update from render instead.

Why is calling a setter during render allowed at all?

So a component can adjust its own state from new props in one pass, as in Cause 4, without an effect and an extra commit. React only allows it for the component that is rendering. Updating another component during render gives a different warning, Cannot update a component while rendering a different component.

Mistakes to avoid

  • Writing onClick={handler()} or onChange={setValue(x)}

  • Copying props into state and syncing them on every render

  • Moving the setter into an effect without asking whether the state is needed at all

  • Guarding a render-time update with a condition that is always true, such as comparing two new arrays

  • Reading only the error text and not the stack trace, which names the component

Practise it in code

Interviewers rarely stop at the definition. These questions open in an editor with tests.

  1. Implement usePrevious() without causing an additional renderMedium35 min
  2. Build linked inputs without effect loops: a Celsius/Fahrenheit converter and a recipe scalerMedium35 min
  3. Debug an infinite useEffect() loop and prevent stale asynchronous responsesMedium35 min
  4. Predict stale closure results in React: timeouts, intervals and event handlersMedium25 min
  5. Predict when React keeps or resets state: position, keys and component typesMedium25 min