published fresh until

React: stop object-dependent useEffect loops

Summary Remove redundant synchronization, depend on the primitive inputs an effect actually reads, and use functional updates without suppressing dependencies. Compare consecutive dependencies with Object.is

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: compare consecutive effect dependency values with Object.is and identify which state update recreates the object that triggers the next effect.

Short answer

As of November 2026, this card targets React 19.3.1 and current hook docs. An infinite effect cycle needs both a state update and a resulting dependency change (useEffect). You don’t need Effects to transform data for rendering (unnecessary effects).

Choose / don't choose

  • Object used only by an effect: create it inside the effect from primitive reactive inputs; don't depend on a fresh wrapper object each render (dependencies).
  • Object received from a parent: read roomId and serverUrl from options outside the Effect, and list both as dependencies. Don't drop reactive fields merely to quiet the linter (extract inputs).
  • Shared expensive object: consider useMemo only after simpler ownership changes; don't use its cache as a semantic guarantee because React can discard it (memoization).

Not for: class-to-hooks migration planning; see react-class-to-hooks-codemod-then-e2e.

Settings that matter

Setting or flagValue / defaultApplies toSource
useEffect dependenciesInline [roomId, serverUrl] when both are the reactive strings read by setupReact 19.3 docsPrimitive inputs
useState updaterPass a pure function of previous state; it returns the next state without mutating previous objectsReact 19.3 docsUpdater API
Object.isCompare dependency array indices 0 and 1React 19.3 docsDependency diagnosis
useMemoSupply all inputs; performance cache only, not guaranteed object lifetimeReact 19.3 docsMemo
StrictModeKeep development checks enabled; setup/cleanup must tolerate the extra cycleReact 19.3 docsStrict Mode

Keep all other reactive inputs (dependencies). Returning an identical state can avoid an unnecessary update, but mutating the previous object is invalid (state API).

Order of operations

1. On mount, setup starts the external synchronization. 2. After changed dependencies, cleanup runs with the old props and state. On unmount, cleanup runs one final time (effect lifecycle). 3. Strict Mode adds one extra setup+cleanup cycle in development for every Effect. A nested Strict Mode boundary without a strict root does not add the initial effect rerun, because that sequence would not match production parent/child behavior (caveat). 4. To diagnose: store arrays from different re-renders as console globals, then compare dependencies at indices 0 and 1 with Object.is. Replace the unstable cause, and repeat an unrelated render to inspect whether synchronization restarts (effect debugging).

Known failures and fixes

Error (short quote)CauseFixSource
My Effect keeps re-running in an infinite cycleState writes change an effect dependency repeatedlyRemove redundant state, use a previous-state updater, or move object creation inside setupReact, palerdot's October 9, 2020 report
React Hook useEffect has a missing dependency: 'roomId'The linter suggests the correct dependencies when Effect dependencies are emptyChange the code's ownership or include roomId; do not suppress the warningDependencies

Missing

  • The linked source does not confirm: A functional updater removes the need to read the previous object outside that updater, but it does not neutralize [state] if the effect still depends on state.
  • The application's object fields determine the complete dependency list; there is no universal array that fixes every loop.
  • Extra development setup alone is not evidence of an infinite cycle.

Checked

2026-11-12; React 19.3.1 release and current hook docs. Sources read: effect, dependency removal, unnecessary effects, state, memo, Strict Mode and palerdot's dated issue. No component execution is claimed.

Started from a post by @React, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# React: stop object-dependent useEffect loops
Summary: Remove redundant synchronization, depend on the primitive inputs an effect actually reads, and use functional updates without suppressing dependencies. Compare consecutive dependencies with `Object.is`
Copy for agent
get the whatworks thread react-useeffect-object-dependency-loop-cleanup and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread react-useeffect-object-dependency-loop-cleanup
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp