Skip to main content
Get started with TanStack Query and learn the core concepts in under 5 minutes.

Prerequisites

Before you begin, make sure you have:
  • Node.js 18+ or Bun installed
  • A JavaScript or TypeScript project set up
  • Basic knowledge of React, Vue, Svelte, Solid, or Angular

Installation

Install TanStack Query for your framework:

Basic Example

Here’s a complete working example using React Query to fetch data from an API:
1

Set up the QueryClient

Create a QueryClient instance and wrap your app with QueryClientProvider:
2

Use the useQuery hook

Fetch data using the useQuery hook:
3

Understand what's happening

Query Key: ['repoData'] is a unique identifier for this query. TanStack Query uses it for caching.Query Function: The async function that fetches your data. It can be any async operation.Query States:
  • isPending: true when the query is loading for the first time
  • error: Contains error object if the query fails
  • data: Contains the fetched data when successful
  • isFetching: true whenever data is being fetched (including background refetches)

Key Features

Automatic Caching

TanStack Query automatically caches your data. If you navigate away and come back, the cached data is shown instantly while fresh data is fetched in the background.

Automatic Refetching

Queries automatically refetch in the background when:
  • The window regains focus
  • The network reconnects
  • A configured refetch interval elapses
You can customize this behavior with options like staleTime, refetchOnWindowFocus, and refetchInterval.

Mutations

Use useMutation to modify data on your server:

Configuration Options

Customize query behavior with options:

Next Steps

Essential Concepts

Learn about query keys, query functions, and caching strategies

Framework Guides

Deep dive into framework-specific usage and patterns

TypeScript

Learn how to use TanStack Query with TypeScript for full type safety

DevTools

Set up the DevTools to debug and inspect your queries