Grokking React Advanced
0% completed
Suspense for Data Fetching
Every component in this chapter that reads data starts with a loading check. PostList returns "Loading posts..." while isPending is true, and only the lines after that check can read data. Chapter 4 showed a different arrangement for code: a lazy component never checks whether its code has arrived, because a Suspense boundary above it shows a fallback until the code is ready. React can do the same for data, and React Query supports it.
The running example is the post viewer from the lesson "Query Keys and Caching", which fetches one post from JSONPlaceholder with the same `fetchPost
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%