MohitDecodes
Back to blogsReact

Common useEffect Mistakes (and When You Don't Need an Effect)

October 24, 2026 · 7 min read

`useEffect` is an escape hatch for synchronizing React with external systems — timers, subscriptions, DOM APIs, or network requests. Using it as a generic "run this whenever state changes" hook creates extra render cycles and subtle bugs.

1. Don't store derived values in Effect + State

// Unnecessary Effect + extra render
const [fullName, setFullName] = useState("");
useEffect(() => setFullName(`${first} ${last}`), [first, last]);

// Compute directly during render
const fullName = `${first} ${last}`;

2. Always clean up async fetches to avoid race conditions

If a user clicks Tab A then quickly clicks Tab B, Tab A's slower network request can resolve *after* Tab B and overwrite the UI with stale data. Use an `AbortController` or a `cancelled` flag in the cleanup function.

  • Compute filtered lists, totals, and formatted labels during render — no `useEffect` needed.
  • Run form submission and button-click logic inside event handlers, not Effects.
  • Return a cleanup function whenever you attach listeners, start intervals, or fetch data.