Stage 2 · Lesson 5 of 8
Effects, and when you do not need one
An keeps a in step with something outside , such as a timer, a browser API or a subscription. You write one with useEffect. It runs after the component renders.
It runs again when a value in its array changes. Its cleanup function runs before the next run and when the component is removed. In you need far fewer effects than older React tutorials suggest.
Initial data is usually fetched in a server component instead. And values you can calculate from props or state should be calculated during render. Reach for an effect only when you truly need to sync with the outside world.
Common trapThe common traps are a missing dependency, which leaves you with a stale old value, and setting state inside an effect that depends on that same state, which loops forever.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- GuideFreeReact Documentation
Meta
Free official course; Thinking in React and Managing State matter most
- CourseFreeNext.js Learn
Vercel · Intermediate
Free official course: the first chapters build pages, layouts and navigation