Vengeance Blog

A Complete Guide to useEffect

Effects synchronize external systems; they are not lifecycle clones.

React Notes1 minInspired by Dan Abramov / Overreacted

Mental model

Use effects for subscriptions, timers, imperative APIs, and other side effects outside React rendering.

Dependencies are a contract

If an effect reads a value, include it in the dependency list or refactor so it no longer depends on that value.

tsx
1useEffect(() => {2  const controller = new AbortController();3  fetchUser(id, { signal: controller.signal });4  return () => controller.abort();5}, [id]);

Avoid these

  • Data transforms that belong in render
  • Chained effects updating state repeatedly
  • Fetching without cancellation