{
  "id": "react/cannot-update-during-existing-state-transition",
  "signature": "Error: Cannot update during an existing state transition (such as within `render`). Render methods should be a pure function of props and state.",
  "signature_zh": "错误：无法在现有的状态转换期间更新（例如在 `render` 中）。渲染方法应是 props 和 state 的纯函数。",
  "regex": "Error: Cannot update during an existing state transition",
  "domain": "react",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A state update (setState) is triggered synchronously inside the render method or a render-phase lifecycle, violating React's rule that render must be pure.",
  "root_cause_type": "generic",
  "root_cause_zh": "在 render 方法或渲染阶段的生命周期中同步触发了状态更新（setState），违反了 React 关于 render 必须是纯函数的规则。",
  "versions": [
    {
      "version": "React 18.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 19.0.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 16.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Any synchronous state update during render is forbidden, regardless of location.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The error is thrown by React internally and cannot be caught by user try-catch.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Move the state update to a useEffect or event handler: instead of `render() { setState(...); }`, use `useEffect(() => { setState(...); }, []);`",
      "success_rate": 0.95,
      "how": "Move the state update to a useEffect or event handler: instead of `render() { setState(...); }`, use `useEffect(() => { setState(...); }, []);`",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the state update depends on props change, use `useEffect` with the relevant prop as dependency: `useEffect(() => { setState(...); }, [prop]);`",
      "success_rate": 0.9,
      "how": "If the state update depends on props change, use `useEffect` with the relevant prop as dependency: `useEffect(() => { setState(...); }, [prop]);`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Move the state update to a useEffect or event handler: instead of `render() { setState(...); }`, use `useEffect(() => { setState(...); }, []);`",
    "If the state update depends on props change, use `useEffect` with the relevant prop as dependency: `useEffect(() => { setState(...); }, [prop]);`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://react.dev/learn/keeping-components-pure",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2024-01-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}