# 错误：超过最大更新深度。当组件在 useEffect 内部调用 setState，但 useEffect 没有依赖数组，或者某个依赖在每次渲染时都发生变化时，可能会发生这种情况。

- **ID:** `react/state-update-in-effect-without-deps`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

带有状态更新的 useEffect 要么缺少依赖数组（每次渲染后运行），要么有一个在每次渲染时都会发生变化的依赖（例如新的对象/函数），从而导致无限循环。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| React 18.2.0 | active | — | — |
| React 17.0.2 | active | — | — |

## 解决方案

1. ```
   Provide a proper dependency array with stable values. If the state update depends on previous state, use the functional update form: setState(prev => prev + 1).
   ```
2. ```
   If the effect needs to react to a changing value, ensure that value is memoized with useMemo or useCallback to maintain referential stability.
   ```

## 无效尝试

- **** — If the effect needs to react to prop or state changes, an empty array makes it run only once, potentially missing updates and causing stale data. (50% 失败率)
- **** — Inline functions/objects are new references each render, so the effect runs every time, defeating the purpose. (85% 失败率)
