The Imperative Loading Problem
What you'll learn: Why managing loading states with useState and useEffect creates scattered, maintenance-heavy code that's hard to reason about.
When you fetch data in React, you've likely written this pattern dozens of times:
const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
setLoading(true);
fetch('/api/data')
.then(res => res.json())
.then(setData)
.catch(setError)
.finally(() => setLoading(false));
}, []);
This imperative approach forces you to manually orchestrate every step: "set loading to true, fetch data, handle success, handle error, set loading to false." It's like being a micromanager who must personally flip every light switch in a building.
The Scattering Problem
As your app grows, this pattern multiplies. Every component that fetches data needs its own loading/error/data triplet. You end up with:
- Repeated boilerplate across dozens of components
- Inconsistent error handling (did you remember
finallyeverywhere?) - Loading state bugs (forgot to set loading back to false in one code path?)
- No coordination between components loading related data
Each component lives in isolation, unaware of what others are doing. Debugging becomes a treasure hunt through scattered useEffect blocks.
The Mental Model Gap
You're thinking: "I need user data." But you're writing: "Set this flag, call this function, update that state, clear this flag, unless there's an error, then set that other flag..." The what gets buried under the how.
Key Takeaway: Imperative loading with useState/useEffect scatters loading logic across components, creating maintenance burdens, inconsistency, and a cognitive gap between what you want (data) and how you get it (manual state orchestration).