Course contentsShow
← React
Lesson 1684 of 2,39641. State Management EcosystemFree lesson

UI State vs Server State

UI toggles, modals, tabs, and dropdowns are local UI concerns; server-fetched data needs different handling.

UI State vs Server State

What you'll learn: How to recognize the fundamental difference between ephemeral UI concerns and server-derived data — and why they need different management approaches.

Two Different Worlds

Not all state is created equal. UI state controls temporary, local interface concerns: is this modal open? Which tab is active? Is this dropdown expanded? This state lives and dies with your component — refresh the page and it's gone.

Server state, on the other hand, is the truth that lives on your backend: user profiles, product listings, shopping carts. It's fetched from APIs and represents data that exists independently of your UI.

Why the Distinction Matters

These two categories have completely different lifecycles and concerns:

UI State characteristics:

  • Synchronous and immediate
  • Lives in component memory
  • No network involved
  • Simple boolean or string values
  • Dies when component unmounts

Server State characteristics:

  • Asynchronous (requires fetching)
  • Might be stale or outdated
  • Needs loading and error states
  • Should be cached and shared
  • Requires revalidation strategies
// UI State: simple, local, synchronous
const [isModalOpen, setIsModalOpen] = useState(false);

// Server State: complex, remote, asynchronous
const [userData, setUserData] = useState(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);

Mixing these concerns leads to chaos. Managing server state with useState means writing your own caching, deduplication, and revalidation logic — essentially reinventing the wheel poorly.

Key Takeaway: UI state (modals, tabs, toggles) should stay local with useState; server state (fetched data) needs specialized tools like React Query or SWR that handle caching, background updates, and synchronization across your app.