Stage 2 · Lesson 6 of 8
Effects and data fetching
useEffect keeps a component in step with something outside , like a network request, a timer or a subscription. An 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. When fetching data, show a and an error state. Also ignore or cancel a response that arrives after the inputs changed.
Otherwise a slow old search can overwrite a newer one. Many effects are not needed at all. If you can calculate a value from props or state, calculate it during render.
Once you have fetched data by hand, try a library such as TanStack Query. It handles caching, retries and refetching, and most real apps use it against their own .
A question to check yourself, an AI practice session and 2 cheat sheet entries 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
- CourseFreeFull Stack Open
University of Helsinki · Intermediate
Free: Parts 0 to 2 cover web basics, React and talking to a server