# 错误：无法在现有的状态转换期间更新（例如在 `render` 中）。渲染方法应是 props 和 state 的纯函数。

- **ID:** `react/cannot-update-during-existing-state-transition`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

在 render 方法或渲染阶段的生命周期中同步触发了状态更新（setState），违反了 React 关于 render 必须是纯函数的规则。

## 版本兼容性

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

## 解决方案

1. ```
   Move the state update to a useEffect or event handler: instead of `render() { setState(...); }`, use `useEffect(() => { setState(...); }, []);`
   ```
2. ```
   If the state update depends on props change, use `useEffect` with the relevant prop as dependency: `useEffect(() => { setState(...); }, [prop]);`
   ```

## 无效尝试

- **** — Any synchronous state update during render is forbidden, regardless of location. (95% 失败率)
- **** — The error is thrown by React internally and cannot be caught by user try-catch. (90% 失败率)
