Courses / React 19: From Components to Production / Chapter 11
Module 5 · Forms and Data Fetching · Chapter 11 of 30
Data Fetching: Requests, Loading States, Races, Caching and Errors
Builds on State and Effects: useState, Events, useEffect and Cleanup, Forms: Controlled and Uncontrolled Inputs, Validation and Form Actions and Advanced Hooks: Refs, Reducers, Context, Layout Effects and Custom Hooks. Next up: Architecting React Apps at Scale: Structure, State and Component APIs.
Part 1 · Where fetching belongs
Four places a request can start
A city air quality dashboard shows readings that live on a server, so every screen has to fetch them somewhere. This chapter builds that fetching step by step against a small fake API running on this machine.
Data fetching means asking a server for data over HTTP and showing what comes back. React does not do this for you. It renders whatever state you hand it, so you choose where the request starts, and that choice decides when the user sees data, how often the request repeats and how much code you must write to keep it correct.
There are four usual starting points, and a fifth that replaces some of them.
| Place | Request starts | Fits | Cost |
|---|---|---|---|
| Event handler | when the user acts |