Stage 3
Stage 3: Advanced
✅ Complete. Every part below has its full lesson (
README.md),examples/,exercises.mdandsolutions/, and the examples and solutions were actually run — see each part's README for real, captured output and../TOOLING.mdfor the verified toolchain.
Goal: Talk to a real API from a component, know when (and when not) to optimize for performance, contain failures gracefully, and prove all of it with a real test suite. Time: ~18 h of lessons + ~6 h project (~24 h total) at 1–1.5 hours a day · Level: Stage 2 done (effects, custom hooks, context, reducer)
Parts in this stage
| Part | Topic | Learning outcomes | Time |
|---|---|---|---|
| 11 | Fetching data | Fetch from a real public API inside useEffect; model loading/error/empty/success as explicit state (not boolean soup); cancel an in-flight request on unmount/re-fetch with AbortController; know why this is taught by hand before any data-fetching library |
~5 h |
| 12 | Performance: useMemo, useCallback, React.memo |
Use the React DevTools profiler to find an actually slow render before touching any memoization API; apply useMemo/useCallback/React.memo correctly; explain why memoizing everything is a common beginner mistake |
~4 h |
| 13 | Error boundaries and code-splitting | Write an error boundary that contains a crash instead of blanking the whole app; lazily load a route/component with React.lazy and Suspense; show a fallback while loading |
~4 h |
| 14 | Testing React components | Write Vitest unit tests for a reducer/hook in isolation; write Testing Library tests that query by role/text like a user would; simulate clicks/typing with user-event; test an async loading/error UI |
~5 h |
Prerequisites for this stage
- Stage 2 complete: effects and cleanup, custom hooks, refs, context, reducer
- Comfortable with
Promise/async/await(from the JS prerequisite)
Stage 3 project {#stage-3-project}
Book Finder — a search app against a free public API (Open Library's search API), chosen because it needs no API key for basic use (the project README pins the exact endpoint):
- A search box that fetches on submit (or debounced on type), with distinct loading/empty/error/success states
- Request cancellation so a fast second search doesn't flicker in a stale first result
- One error boundary around the results panel
- A Vitest + Testing Library suite covering: a successful search, an empty-results search, and a failed request
Acceptance sketch (the project README has the final checklist):
- No request race: typing a new query cannot show a stale older response
- Error state is reachable and tested (e.g. by mocking a failed fetch)
- At least one component is code-split with
React.lazy/Suspense - Test suite passes under
vitest runwith no network calls hitting the real API (mocked)