{
  "id": "react/effect-cleanup-not-a-function",
  "signature": "Warning: useEffect must not return anything besides a function, which is used for clean-up. You returned: undefined.",
  "signature_zh": "警告：useEffect 不能返回除函数之外的任何内容，该函数用于清理。你返回了：undefined。",
  "regex": "useEffect must not return anything besides a function, which is used for clean-up",
  "domain": "react",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The callback passed to useEffect returns a value that is not a function (e.g., undefined, null, an object, or a Promise), which violates the rule that the return value must be a cleanup function or nothing.",
  "root_cause_type": "generic",
  "root_cause_zh": "传递给 useEffect 的回调返回了一个非函数的值（例如 undefined、null、对象或 Promise），违反了返回值必须是清理函数或无返回值的规则。",
  "versions": [
    {
      "version": "React 16.8+",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 17.0.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "React 18.2.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Adding an empty return statement (return;)",
      "why_fails": "This is actually correct if the function returns nothing, but if the problem is an async function, adding return; doesn't fix the implicit Promise return.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    },
    {
      "action": "Wrapping the async code in a separate function and calling it",
      "why_fails": "If the async function is still used as the effect callback, it still returns a Promise. The fix is to define async inside the effect, not as the effect itself.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "Using useEffect(async () => { ... }, [])",
      "why_fails": "An async function always returns a Promise, which is not a valid cleanup function. React will fire this warning and the cleanup may not work.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "If you need async operations, define an async function inside the effect and call it immediately: useEffect(() => { const fetchData = async () => { ... }; fetchData(); }, []);",
      "success_rate": 0.95,
      "how": "If you need async operations, define an async function inside the effect and call it immediately: useEffect(() => { const fetchData = async () => { ... }; fetchData(); }, []);",
      "condition": "",
      "sources": []
    },
    {
      "action": "If you need a cleanup function, return a function explicitly: useEffect(() => { const subscription = source.subscribe(); return () => { subscription.unsubscribe(); }; }, []);",
      "success_rate": 0.9,
      "how": "If you need a cleanup function, return a function explicitly: useEffect(() => { const subscription = source.subscribe(); return () => { subscription.unsubscribe(); }; }, []);",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "If you need async operations, define an async function inside the effect and call it immediately: useEffect(() => { const fetchData = async () => { ... }; fetchData(); }, []);",
    "If you need a cleanup function, return a function explicitly: useEffect(() => { const subscription = source.subscribe(); return () => { subscription.unsubscribe(); }; }, []);"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://reactjs.org/docs/hooks-effect.html#effects-with-cleanup",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-04-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}