Fetching a list on mount
The most common Read operation: load data when a page first appears.- Backend (Python)
- API Client (JS)
The component — loading, error, data
- Loading — show a spinner or “Loading…” text
- Error — show what went wrong
- Empty — data loaded but the list is empty
- Data — render the list
Fetching a single record
For detail pages (e.g.,/users/3), fetch one record by ID:
- Backend (Python)
- API Client (JS)
Notice
[userId] in the dependency array. If the user navigates from one profile to another, userId changes and the effect re-runs — fetching the new user automatically.Rendering with components
Break the display into reusable components:UserList) handles state and fetching. The presentational component (UserCard) just displays data. This is the composition pattern from the React Essentials section.
The companion repo’s
User shape is intentionally simple: id, name, and email. If you add fields later (like role), this same read pattern still works — you just render the new properties.Search and filter
Add client-side filtering to your list:Refreshing data
Sometimes you need to reload data — after creating, updating, or deleting:What’s next?
You can create and read records. Now let’s add editing — loading existing data into a form and sending updates back to the API.Update operation
Edit existing records with a form that sends PUT requests to your API