Client-Side Fetching: The Hidden Cost
You'll learn: Why fetching data in useEffect delays your user experience and creates unnecessary loading states.
When you fetch data in useEffect, you're introducing a chain reaction of delays that users feel but rarely understand. Here's what actually happens:
- Your component renders (empty, showing nothing useful)
- React paints that empty render to the screen
- Then your effect fires and starts the fetch
- The network request travels to the server and back
- Finally, you have data to show
This pattern adds latency on top of latency. The user stares at a loading spinner while waiting for a process that could have started earlier.
The Waterfall Problem
Think of it like ordering at a restaurant: You sit down, look at the menu, then call the waiter, then place your order. What if the kitchen could start preparing your usual order the moment you walked in the door?
Client-side fetching in useEffect is the "wait for the waiter" approach. Every component that needs data creates its own loading state, its own spinner, its own delay. If you have nested components that each fetch their own data, these delays stack — a waterfall of waiting.
The Hidden Costs
- User experience: Extra loading states mean more spinners, more layout shifts
- Performance: Your app feels slower than it needs to be
- Code complexity: You're managing loading/error/success states manually
- Wasted renders: Empty render → loading render → data render (three renders for one piece of data)
Modern patterns like server components, loader functions, or libraries like TanStack Query start fetching before or during render, cutting out the "wait for the waiter" step entirely.
Key Takeaway: Fetching in useEffect adds unnecessary latency because it waits until after the component renders and paints — modern approaches fetch earlier in the lifecycle, delivering faster experiences.