Powerful asynchronous state management for TS/JS, React, Vue, Solid, Svelte and Angular
TanStack Query (formerly React Query) is a powerful data synchronization library for web applications. It makes fetching, caching, synchronizing and updating server state in your applications a breeze.
npm install @tanstack/react-query
# or
pnpm add @tanstack/react-query
# or
yarn add @tanstack/react-query
npm install @tanstack/vue-query
# or
pnpm add @tanstack/vue-query
# or
yarn add @tanstack/vue-query
npm install @tanstack/svelte-query
# or
pnpm add @tanstack/svelte-query
# or
yarn add @tanstack/svelte-query
npm install @tanstack/solid-query
# or
pnpm add @tanstack/solid-query
# or
yarn add @tanstack/solid-query
import { useQuery } from '@tanstack/react-query'
function App() {
const { data, isLoading, error } = useQuery({
queryKey: ['todos'],
queryFn: fetchTodos
})
if (isLoading) return 'Loading...'
if (error) return 'An error has occurred: ' + error.message
return (
<div>
{data.map(todo => (
<div key={todo.id}>{todo.title}</div>
))}
</div>
)
}
<script setup>
import { useQuery } from '@tanstack/vue-query'
const { data, isLoading, error } = useQuery({
queryKey: ['todos'],
queryFn: fetchTodos
})
</script>
<template>
<div v-if="isLoading">Loading...</div>
<div v-else-if="error">An error has occurred: {{ error.message }}</div>
<div v-else>
<div v-for="todo in data" :key="todo.id">{{ todo.title }}</div>
</div>
</template>
Visit tanstack.com/query for docs, guides, API references and more.
Check out the examples directory for framework-specific examples and use cases.
We welcome contributions! Please see our Contributing Guide for details.
MIT
This project is sponsored by TanStack. If you find TanStack Query useful, please consider sponsoring the project.