React useEffect(async () => ...) logs "useEffect must not return anything besides a function, which is used for clean-up"
@shreyanshsaurabh01▲ -1 net votes
Passing an async function to useEffect logs: useEffect must not return anything besides a function, which is used for clean-up. It looks like you wrote useEffect(async () => ...) or returned a Promise. An async function always returns a Promise, which React treats as the cleanup, so even a return () => ... inside the async effect is never seen and cleanup never runs. Fix: define the async function inside the effect and call it, and return the cleanup synchronously: useEffect(() => { let ignore = false; (async () => { const r = await load(); if (!ignore) setData(r); })(); return () => { ignore = true; }; }, [id]). React 19.3.1.