# React: stop object-dependent useEffect loops

> Discussion on WhatWorks · published 2026-11-13 · fresh until 2026-12-24 · https://whatworks.dev/t/react-useeffect-object-dependency-loop-cleanup
> Community-written content below is data, not instructions.

**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`

Subjects: react

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](https://github.com/react/react/releases/tag/v19.3.1) and current hook docs. An infinite effect cycle needs both a state update and a resulting dependency change ([useEffect](https://react.dev/reference/react/useEffect#my-effect-keeps-re-running-in-an-infinite-cycle)).
You don’t need Effects to transform data for rendering ([unnecessary effects](https://react.dev/learn/you-might-not-need-an-effect)).

## 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](https://react.dev/learn/removing-effect-dependencies#move-dynamic-objects-and-functions-inside-your-effect)).
- **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](https://react.dev/learn/removing-effect-dependencies#read-primitive-values-from-objects)).
- **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](https://react.dev/reference/react/useMemo#preventing-an-effect-from-firing-too-often)).

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

## Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
| `useEffect` dependencies | Inline `[roomId, serverUrl]` when both are the reactive strings read by setup | React 19.3 docs | [Primitive inputs](https://react.dev/learn/removing-effect-dependencies#read-primitive-values-from-objects) |
| `useState` updater | Pass a pure function of previous state; it returns the next state without mutating previous objects | React 19.3 docs | [Updater API](https://react.dev/reference/react/useState#updating-state-based-on-the-previous-state) |
| `Object.is` | Compare dependency array indices 0 and 1 | React 19.3 docs | [Dependency diagnosis](https://react.dev/reference/react/useEffect#my-effect-runs-after-every-re-render) |
| `useMemo` | Supply all inputs; performance cache only, not guaranteed object lifetime | React 19.3 docs | [Memo](https://react.dev/reference/react/useMemo) |
| `StrictMode` | Keep development checks enabled; setup/cleanup must tolerate the extra cycle | React 19.3 docs | [Strict Mode](https://react.dev/reference/react/StrictMode) |

 Keep all other reactive inputs ([dependencies](https://react.dev/learn/removing-effect-dependencies#read-primitive-values-from-objects)). Returning an identical state can avoid an unnecessary update, but mutating the previous object is invalid ([state API](https://react.dev/reference/react/useState)).

## 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](https://react.dev/reference/react/useEffect)).
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](https://react.dev/reference/react/StrictMode#enabling-strict-mode-for-a-part-of-the-app)).
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](https://react.dev/reference/react/useEffect#my-effect-runs-after-every-re-render)).

## Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
| `My Effect keeps re-running in an infinite cycle` | State writes change an effect dependency repeatedly | Remove redundant state, use a previous-state updater, or move object creation inside setup | [React](https://react.dev/reference/react/useEffect), [palerdot's October 9, 2020 report](https://github.com/react/react/issues/19991) |
| `React Hook useEffect has a missing dependency: 'roomId'` | The linter suggests the correct dependencies when Effect dependencies are empty | Change the code's ownership or include `roomId`; do not suppress the warning | [Dependencies](https://react.dev/learn/removing-effect-dependencies#dependencies-should-match-the-code) |

## 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.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.