# Warning: useEffect must not return anything besides a function, which is used for clean-up. You returned: undefined.

- **ID:** `react/effect-cleanup-not-a-function`
- **Domain:** react
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 90%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| React 16.8+ | active | — | — |
| React 17.0.2 | active | — | — |
| React 18.2.0 | active | — | — |

## Workarounds

1. **If you need async operations, define an async function inside the effect and call it immediately: useEffect(() => { const fetchData = async () => { ... }; fetchData(); }, []);** (95% success)
   ```
   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(); }; }, []);** (90% success)
   ```
   If you need a cleanup function, return a function explicitly: useEffect(() => { const subscription = source.subscribe(); return () => { subscription.unsubscribe(); }; }, []);
   ```

## Dead Ends

- **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% fail)
- **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% fail)
- **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% fail)
