reactseverity: workaround
#185

React Error #185: Maximum update depth exceeded

Maximum update depth exceeded

90% fixable~10 mindifficulty: intermediate

Verified against React 19 source (ReactFiberWorkLoop.js), GitHub issue #6895 (1.3k reactions), React docs: synchronizing-with-effects · Updated April 2026

> quick_fix

A component is calling setState inside a render or an un-dependency-guarded useEffect. Move the setState call inside an event handler, add the missing dependency, or gate it with a condition.

// ❌ Causes #185 (setState during render)
function Bad() {
  const [n, setN] = useState(0)
  setN(n + 1)  // runs on every render
  return <p>{n}</p>
}

// ✅ Fix: gate with useEffect + dependency
function Good({ userId }) {
  const [n, setN] = useState(0)
  useEffect(() => { setN(x => x + 1) }, [userId])
  return <p>{n}</p>
}

What causes this error

React limits any component to 50 consecutive synchronous re-renders to catch infinite loops. Error #185 means your component crossed that limit. Common patterns: setState during render, setState inside an un-dependency-guarded useEffect, or a reducer that dispatches a new action on every render.

> advertisementAdSense placeholder

How to fix it

  1. 01

    step 1

    Find the component name in the stack trace

    React usually points you at the component. Open it and look for setState calls outside event handlers.

  2. 02

    step 2

    Check every useEffect for its dependency array

    An empty array [] means run once. A missing array means run on every render. Any state you set in the effect must be gated by a dependency.

  3. 03

    step 3

    Use the updater form for state that depends on itself

    Instead of setN(n + 1), write setN(x => x + 1). This prevents a stale closure that can cause loops.

    // ❌ Stale closure — may loop
    useEffect(() => { setN(n + 1) }, [])
    
    // ✅ Updater — safe
    useEffect(() => { setN(x => x + 1) }, [])
  4. 04

    step 4

    If rendering a list, confirm keys are stable

    Unstable keys cause React to unmount+remount children, which re-fires their useEffect chains.

Frequently asked questions

What is error #185 in React?

Maximum update depth exceeded — a component triggered more than 50 synchronous re-renders. Almost always an unintentional setState loop.

How do I find which useEffect is the problem?

Temporarily disable your useEffects one at a time. The loop will stop when you disable the culprit.

Can React Strict Mode cause #185?

No. Strict Mode doubles renders in development but does not re-trigger infinite loops.

disclosure:Errordex runs AdSense and has zero affiliate links or sponsored content. Every fix is manually verified against official sources listed in the “sources” sidebar. If a fix here didn’t work for you, please email so we can update the page.