← React Field Guide
Concept 10 of 11
Effects
✦ Tap any highlighted term to learn more
lets you run code after a . Use it for things that need to reach outside of React: updating the document title, setting up a timer, subscribing to an , or starting a network request.
takes two arguments: the effect , and a dependency . The dependency controls when the effect re-runs. If you pass [count], the effect runs whenever count changes.
An empty [] means the effect runs once — after the first only. No means it runs after every . Missing the dependency when you meant to use [] is a very common bug.
Effects can return a cleanup . React calls it before running the effect again, and when the unmounts. Use cleanup to clear timers, cancel subscriptions, and avoid memory leaks.