{
  "id": "react/maximum-update-depth-exceeded-useeffect",
  "signature": "Error: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect without a dependency array",
  "signature_zh": "错误：超过最大更新深度。这可能发生在组件在 useEffect 内调用 setState 而没有依赖数组时",
  "regex": "Error: Maximum update depth exceeded\\. This can happen when a component calls setState inside useEffect",
  "domain": "react",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A useEffect calls setState without specifying dependencies, causing an infinite loop of render → effect → setState → render.",
  "root_cause_type": "generic",
  "root_cause_zh": "useEffect 调用 setState 时未指定依赖项，导致渲染 → 副作用 → setState → 渲染的无限循环。",
  "versions": [
    {
      "version": "React 16.8+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 17",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 18",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 19",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Does not address the root cause; the useEffect still runs without dependencies, triggering setState on every render.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Causes an infinite loop during render because setState triggers a re-render immediately.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The condition may still be true on every render, or the effect runs on every render anyway, leading to the same loop.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Add a dependency array to useEffect with the values that should trigger the effect:\n\nuseEffect(() => {\n  setCount(count + 1);\n}, [count]); // Now it only runs when count changes, avoiding infinite loop if count is not updated in a way that causes re-render",
      "success_rate": 0.95,
      "how": "Add a dependency array to useEffect with the values that should trigger the effect:\n\nuseEffect(() => {\n  setCount(count + 1);\n}, [count]); // Now it only runs when count changes, avoiding infinite loop if count is not updated in a way that causes re-render",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use the functional update form of setState and an empty dependency array if the effect should run only once:\n\nuseEffect(() => {\n  setCount(prev => prev + 1);\n}, []); // Runs once on mount",
      "success_rate": 0.9,
      "how": "Use the functional update form of setState and an empty dependency array if the effect should run only once:\n\nuseEffect(() => {\n  setCount(prev => prev + 1);\n}, []); // Runs once on mount",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the effect depends on props or state that change, use useReducer to manage complex state transitions and avoid direct setState in effects.",
      "success_rate": 0.85,
      "how": "If the effect depends on props or state that change, use useReducer to manage complex state transitions and avoid direct setState in effects.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Add a dependency array to useEffect with the values that should trigger the effect:\n\nuseEffect(() => {\n  setCount(count + 1);\n}, [count]); // Now it only runs when count changes, avoiding infinite loop if count is not updated in a way that causes re-render",
    "Use the functional update form of setState and an empty dependency array if the effect should run only once:\n\nuseEffect(() => {\n  setCount(prev => prev + 1);\n}, []); // Runs once on mount",
    "If the effect depends on props or state that change, use useReducer to manage complex state transitions and avoid direct setState in effects."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://react.dev/reference/react/useEffect",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.9,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-01-10",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}