Data fetching

TanStack Query / SWR

Our pick

TanStack Query

Lots of people use it and it can do a lot. Not just displaying data — you can write saving and deleting the same way

Compare the result

We built the same thing with each library. Try them out.

TanStack Query
SWR

Compare the code

Edit the code and the preview on the right updates.

import {
  QueryClient,
  QueryClientProvider,
  useQuery,
} from "@tanstack/react-query"
import { fetchEmployees } from "./api"
import { EmployeeListView, ErrorView, LoadingView } from "./view"

// The cache that remembers fetched data (one per app)
const queryClient = new QueryClient()

function EmployeeList() {
  const { data, isPending, error } = useQuery({
    queryKey: ["employees"],
    queryFn: fetchEmployees,
  })

  if (isPending) return <LoadingView />
  if (error) return <ErrorView message={error.message} />

  return <EmployeeListView employees={data} />
}

export default function App() {
  return (
    // Wrap the whole app in QueryClientProvider to use useQuery inside it
    <QueryClientProvider client={queryClient}>
      <EmployeeList />
    </QueryClientProvider>
  )
}

Comparison

As of October 2026

TanStack Query

Our pickOfficial site ↗

Features

Fetches data, caches it, and refetches when it gets stale, all in one. It also has strong support for saving and deleting (changing data)

Best for

The safe default. Apps that show and update lots of data, like admin screens

Features

A library from Vercel, the makers of Next.js. Fetch data with a single line of useSWR. Small and simple

Best for

You build with Next.js. Simple screens that only display data