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

- **ID:** `react/useEffect-return-not-function`
- **领域:** react
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

useEffect 回调返回了一个不是函数或 undefined 的值，违反了 React 对 effect 清理的约定。

## 版本兼容性

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

## 解决方案

1. ```
   确保 useEffect 回调不返回任何内容（undefined）或返回一个清理函数。示例：useEffect(() => { const timer = setInterval(...); return () => clearInterval(timer); }, []);
   ```
2. ```
   如果需要异步逻辑，在 effect 内部定义异步函数并调用它，但不要返回 promise。示例：useEffect(() => { const fetchData = async () => { ... }; fetchData(); }, []);
   ```

## 无效尝试

- **Returning null or false from useEffect to suppress the warning.** — React expects either undefined (no cleanup) or a function; returning null/false triggers the same error because they are not functions. (90% 失败率)
- **Removing the return statement entirely even when cleanup is needed.** — Without a cleanup function, subscriptions, timers, or event listeners may persist, causing memory leaks or duplicate effects. (70% 失败率)
- **Wrapping the return value in an async function (e.g., useEffect(async () => { ... return someValue; })).** — Async functions always return a Promise, which is not a function for cleanup; React will throw the same error. (95% 失败率)
