Data Fetching
Part of the React course
Almost no real app can get by showing only data the user already has on their screen. At some point a component needs to ask a server for something, a list of users, a product's details, a page of search results, and until that answer comes back there is a gap of time where the component has nothing to show yet, and a real chance the answer never comes back at all because the network failed.
Calling a server is a side effect, something that reaches outside of "compute this component's JSX from its current props and state," in the same family as starting a timer or opening a connection. If you called fetch directly in a component's body, it would fire on every single render, including renders that happened for reasons that have nothing to do with needing fresh data, and each of those calls would...
Want to learn React Data Fetching in a real environment?
Click below, get a fresh Linux box with React ready to go, and work through Data Fetching hands-on with an AI tutor that knows your code.
Start this lessonData FetchingWhat you'll learn
- Fetch inside useEffect
- Loading/error/data states
- AbortController cleanup
- Preventing setState after unmount
- Mention TanStack Query as a next step
