pkgdocs/compare/react-query vs swr

Comparing

npm

react-query

Hooks for managing, caching and syncing asynchronous and remote data in React

1.6M/ wk
v3.39.3
vs
npm

swr

React data fetching with stale-while-revalidate caching — one hook for all your remote data needs with automatic revalidation.

3.5M/ wk
v2.3.3
Metricreact-queryswr
Ecosystemnpmnpm
DifficultyBeginnerBeginner
Weekly downloads1.6M3.5M↑
Latest versionv3.39.3v2.3.3
Recipes12↑

Tags

react-query only

server-statetypescriptcachedatafetchgraphql

Shared

reactdata-fetchingcachingasync

swr only

hooks

When to use each

react-query

Use React Query for any React app that fetches server data: REST APIs, GraphQL, or any async function. It replaces 95% of the useEffect+useState patterns for data fetching and adds caching, background refetching, and optimistic updates for free.

swr

Read-heavy React apps: dashboards, profiles, lists. When you want simple cache-first data with background refresh. When components far apart need to share server data without prop drilling.

When to skip each

react-query

React Query is for server state (data that lives on a server). For UI state (modals, form values, local toggles), use useState or Zustand. If you're already using a full data layer like Apollo Client for GraphQL, React Query is redundant.

swr

Complex mutation workflows with optimistic updates and rollbacks (react-query/TanStack Query is more powerful for this). Server-side rendering where you need full control over data fetching timing.

Sample recipes

react-query

  • Install react-query

swr

  • Fetch and display data with loading state
  • Mutate cache after an update