TanStack Query Data Fetching
github.com
3
Leaving SiteNav
External Link Disclaimer
You are about to visit github.com. This website is not operated by us. We are not responsible for its content or privacy practices.
About this website
TanStack Query (formerly React Query) is a free and open-source data-fetching and state management library for React, Vue, Solid, and Svelte applications. Created by Tanner Linsley (also the creator of React Table) in 2019, TanStack Query has become the standard for server state management, used by millions of projects. Key features: server state management: TanStack Query distinguishes between client state (UI state managed by useState or Zustand) and server state (data fetched from APIs). Server state is asynchronous, can be shared across components, and needs caching, synchronization, and background updates. Caching: queries are automatically cached by query key. Components requesting the same data receive cached results instantly, with background refetching. Configurable staleTime (how long data is fresh) and cacheTime (how long unused data stays in cache). Automatic background updates: when a query becomes stale (after staleTime), TanStack Query refetches in the background, ensuring data is always fresh without manual triggers. Window refocus: optionally refetch on window focus. Mutations: useMutation handles data modifications (POST, PUT, DELETE). Mutations can automatically invalidate and refetch affected queries via queryClient.invalidateQueries. Optimistic updates: update the cache before the mutation completes, rolling back on error. DevTools: TanStack Query DevTools browser extension for inspecting queries, mutations, and cache state. Pagination and infinite scroll: useQuery with pagination parameters, useInfiniteQuery for infinite scrolling with cursor-based loading. Prefetching: queryClient.prefetchQuery loads data before navigation for instant page loads. SSR: server-side rendering support with hydration. TypeScript-first: fully typed APIs with inference. Framework adapters: @tanstack/react-query, @tanstack/vue-query, @tanstack/solid-query, @tanstack/svelte-query. JavaScript/TypeScript. MIT.
Statistics
3
Views
0
Clicks
0
Like
0
Dislike