# 警告：useEffect 不能返回除函数以外的任何内容，函数用于清理。看起来你写了 useEffect(async () => ...) 或返回了一个 Promise。

- **ID:** `react/useeffect-cleanup-return-promise`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

useEffect 的清理函数必须是 undefined 或同步函数。返回 Promise（例如来自 async 函数）会导致此警告，因为 React 无法在清理上调用 .then()。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| React 16.8+ | active | — | — |
| React 17.x | active | — | — |
| React 18.x | active | — | — |

## 解决方案

1. ```
   Define an async function inside useEffect and call it immediately, then return a cleanup function. Example: useEffect(() => { const fetchData = async () => { /* ... */ }; fetchData(); return () => { /* cleanup */ }; }, []);
   ```
2. ```
   Use a custom hook like useAsyncEffect from a library (e.g., react-use) that handles async effects properly.
   ```
3. ```
   For simple cases, use .then() and .catch() instead of async/await: useEffect(() => { fetch('/data').then(setData).catch(handleError); return () => { /* cleanup */ }; }, []);
   ```

## 无效尝试

- **** — The async function still returns a Promise, which React interprets as an invalid cleanup return value. (90% 失败率)
- **** — Promise.resolve() returns a Promise, still violating the rule that cleanup must be a function or undefined. (85% 失败率)
- **** — The return value of the async function is a Promise, regardless of wrapping. (80% 失败率)
