# 警告：useEffect 不能返回除函数之外的任何内容，该函数用于清理。你返回了：undefined。

- **ID:** `react/effect-cleanup-not-a-function`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

传递给 useEffect 的回调返回了一个非函数的值（例如 undefined、null、对象或 Promise），违反了返回值必须是清理函数或无返回值的规则。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| React 16.8+ | active | — | — |
| React 17.0.2 | active | — | — |
| React 18.2.0 | active | — | — |

## 解决方案

1. ```
   If you need async operations, define an async function inside the effect and call it immediately: useEffect(() => { const fetchData = async () => { ... }; fetchData(); }, []);
   ```
2. ```
   If you need a cleanup function, return a function explicitly: useEffect(() => { const subscription = source.subscribe(); return () => { subscription.unsubscribe(); }; }, []);
   ```

## 无效尝试

- **Adding an empty return statement (return;)** — 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. (30% 失败率)
- **Wrapping the async code in a separate function and calling it** — 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. (40% 失败率)
- **Using useEffect(async () => { ... }, [])** — 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. (70% 失败率)
