Course contentsShow
← React
Lesson 1482 of 2,39637. React 19 and BeyondFree lesson

When use() Fits vs TanStack Query or Loaders

Comparing use() to established data fetching solutions and identifying scenarios where each approach shines.

When use() Fits vs TanStack Query or Loaders

You'll learn when to reach for use() versus more established data fetching solutions like TanStack Query or framework loaders.

The Landscape of Data Fetching

React's use() hook is powerful, but it's not a silver bullet that replaces all other data fetching patterns. Think of it like choosing between a Swiss Army knife, a full toolbox, or a specialized power tool—each has its place.

When use() Shines

use() excels when:

  • You already have a promise from a server component or parent that you need to unwrap in a client component
  • You're doing simple, one-time data reads without complex caching needs
  • You want minimal setup for proof-of-concepts or simple apps
  • Your data fetching is tightly coupled to component rendering via Suspense

When TanStack Query Wins

TanStack Query (React Query) is better when you need:

  • Automatic refetching on window focus, intervals, or network reconnect
  • Sophisticated caching strategies with stale-while-revalidate patterns
  • Optimistic updates and mutations with rollback logic
  • DevTools for debugging cache state and query lifecycles
  • Request deduplication across your entire app

When Framework Loaders Fit

Router-level loaders (like Remix or React Router) excel at:

  • Route-level data requirements that block navigation
  • SEO-critical data that must be server-rendered
  • Parallel data fetching for nested routes before rendering

The Practical Decision

If you're building a feature-rich app with complex data needs, TanStack Query's ecosystem is worth the dependency. If your framework provides loaders, use them for route data. Reserve use() for simple promise consumption, especially when integrating server and client components or when you want React to handle Suspense without additional libraries.

Key Takeaway: use() is best for simple promise unwrapping in Suspense contexts; use TanStack Query for complex caching/refetching needs and framework loaders for route-level data requirements.