# 错误：重新渲染次数过多。React 限制了渲染次数以防止无限循环。

- **ID:** `react/too-many-re-renders-infinite-loop`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

组件的状态更新触发了重新渲染，而重新渲染又同步触发了另一个状态更新（例如，在 render 函数体中直接调用 setState，或在依赖项不正确的 effect 中调用），导致无限循环。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| react@16.8.0+ | active | — | — |
| react@17.0.2 | active | — | — |
| react@18.2.0 | active | — | — |

## 解决方案

1. ```
   Ensure state updates are not called directly in the render body. Move them to event handlers or useEffect with proper dependencies.
   ```
2. ```
   If using useEffect, ensure the dependency array is correct and does not include variables that change on every render unnecessarily.
   ```

## 无效尝试

- **** — There is no configurable limit; React hardcodes the limit to prevent infinite loops. Increasing it would only delay the crash. (95% 失败率)
- **** — useCallback does not prevent the infinite loop; it only prevents unnecessary re-creation of functions. The loop is caused by the call itself, not the function identity. (70% 失败率)
- **** — While this may break the synchronous loop, it is a hack that leads to unpredictable behavior and does not address the root cause. (60% 失败率)
