API reference
TanStack API reference
TanStack Query, Router and Table
- Identifiers
- 111
- With full guides
- 88
- Types
- 7
Topics covered
- Query basics
- Caching & staleTime
- Mutations
- Invalidation
- Infinite queries
- Optimistic updates
- TanStack Router
- TanStack Table
Class
| Name | What it does |
|---|---|
QueryClient | QueryClient is TanStack Query’s imperative interface for interacting with query and mutation caches. It also owns client-level defaults and methods for fetching, reading, updating, and managing cached data. |
QueryCache | QueryCache stores TanStack Query's query data, metadata, and state. It supports creating, finding, clearing, and observing cached queries, but applications normally use QueryClient instead. |
MutationCache | MutationCache stores mutations and is normally accessed through QueryClient. It supports inspecting, filtering, clearing, and subscribing to mutation-cache updates. |
QueryObserver | QueryObserver observes one query and produces a QueryObserverResult from its state. It supports framework adapters and direct, framework-independent subscriptions. |
InfiniteQueryObserver | InfiniteQueryObserver watches an infinite query and adds page-oriented state and methods to the base QueryObserver result. It is the core primitive behind framework-level infinite-query hooks. |
Store | Store is TanStack Store's writable reactive container. It holds typed state, supports updates and subscriptions, and can expose optional typed actions. |
Virtualizer | |
FormApi | FormApi is TanStack Form’s core class for managing form state, validation, and submission. Framework adapters usually create it through hooks or factory functions, but it can be constructed directly when needed. |
FieldApi | FieldApi manages the state and behavior of one TanStack Form field. Framework hooks or field-creation functions normally create it so it participates in the framework's reactivity model. |
QueryErrorResetBoundary | QueryErrorResetBoundary scopes query-error resets to a component subtree. Give its render-prop reset function to an error boundary so a retry action can clear query errors before rendering again. |
IsRestoringProvider | IsRestoringProvider is the Solid context provider for persisted query-client restoration state. It exposes an accessor<boolean> that useIsRestoring and query primitives can consume. |
Component
| Name | What it does |
|---|---|
QueryClientProvider | QueryClientProvider supplies a QueryClient to a React component tree. It also manages the client's mount and unmount lifecycle. |
HydrationBoundary | HydrationBoundary places previously dehydrated query state into a QueryClient for a rendered subtree. It merges overlapping data by freshness and always renders its children. |
RouterProvider | RouterProvider mounts a configured TanStack Router in a React application. Pass the router instance through its router prop, usually at the application root. |
Link | TanStack Router's Link creates typed, declarative navigation to a new location. It renders a real anchor with a valid href and supports route parameters, search parameters, hashes, state, active styling, and preloading. |
Outlet | TanStack Router's Outlet renders the next matching child route inside a parent route component. It takes no props and renders null when no child route matches. |
Function
| Name | What it does |
|---|---|
queryOptions | queryOptions builds reusable, type-safe TanStack Query configurations. The returned options work with hooks and imperative QueryClient APIs while carrying query data and error types through the query key. |
createRouter | Creates a TanStack Router instance from a RouterOptions object. The required route tree and other router-wide settings are supplied through that object. |
createColumnHelper | Creates a typed helper for authoring TanStack Table column definitions. It improves inference for accessor values, display and group columns, and arrays of nested definitions. |
infiniteQueryOptions | Build reusable, type-safe options for an infinite query. The returned query key carries the query's infinite-data and error types across TanStack Query APIs. |
hydrate | Restores a dehydrated TanStack Query cache snapshot into a QueryClient, commonly transferring prefetched server data to the client. Existing entries are updated only when the incoming data is newer. |
dehydrate | Converts a QueryClient cache into a serializable DehydratedState for transferring prefetched data, commonly from server to client. It includes successful queries and paused mutations by default, with options for selection and transformation. |
isCancelledError | |
keepPreviousData | Keeps a query's previous result visible as placeholder data while a changed query key fetches its new result. Pass the function to placeholderData. |
matchQuery | Tests whether a Query satisfies the supplied QueryFilters. It returns true only when every provided filter matches. |
replaceEqualDeep | Returns the previous value when it is deeply equal to the new value; otherwise, it reuses equal nested parts from the previous value. This supports structural sharing for JSON-like data. |
getCoreRowModel | getCoreRowModel provides TanStack Table's unmodified starting row model. It maps the table's original data into rows before other row-model features process them. |
getSortedRowModel | |
getFilteredRowModel | getFilteredRowModel configures the row model used for client-side column filtering. The table instance exposes the resulting filtered rows through the same-named method. |
getPaginationRowModel | Creates the row-model factory used for client-side pagination in TanStack Table. It exposes only the rows belonging to the current page. |
getGroupedRowModel | getGroupedRowModel is a deprecated TanStack Table v8 compatibility stub that enables the grouped row model. For current Table APIs, use createGroupedRowModel() in the groupedRowModel feature slot. |
getExpandedRowModel | getExpandedRowModel enables client-side row expansion in TanStack Table. It returns the expanded row model for use in the table's row-model pipeline. |
getFacetedRowModel | getFacetedRowModel is a deprecated legacy compatibility marker for TanStack Table v8 faceting. For current tables, register createFacetedRowModel() in the facetedRowModel feature slot instead. |
getFacetedUniqueValues | Returns a Map of unique facet values to their occurrence counts. Use it to build checkbox lists, select menus, autocomplete suggestions, or other faceted controls. |
flexRender | |
createRoute | createRoute creates a TanStack Router Route instance from a RouteOptions object. Add the instance to a parent route’s children to build the route tree passed to the router. |
createRootRoute | Creates the top-level route for a TanStack Router route tree. Configure it with route options, attach child routes, and pass the resulting tree to createRouter. |
createFileRoute | Creates a file-based TanStack Router route from its generated path. The returned function accepts RouteOptions and produces the configured route instance used in the generated route tree. |
createRootRouteWithContext | Creates a typed root-route factory whose context contract must be satisfied when the router is created. Use it to make router context available with consistent types across the route tree. |
lazyRouteComponent | Creates a one-off, code-split TanStack Router route component. The returned lazy component can be preloaded, and an optional export name supports named exports. |
redirect | TanStack Router's redirect function creates a Redirect object that can be returned or thrown to navigate from route callbacks. The throw option controls whether the object is thrown immediately. |
notFound | Creates a TanStack Router not-found error for missing resources or route handling. Return it or throw it from beforeLoad or loader callbacks, with options available to select handling and control throwing. |
formOptions | |
elementScroll | |
windowScroll | windowScroll is TanStack Virtual’s built-in implementation for scrolling a virtualizer through the browser window. Framework adapters such as useWindowVirtualizer configure it automatically. |
createLazyFileRoute | Creates a partial file-based route whose non-critical configuration is loaded lazily when the route matches. It is intended for route-level code splitting. |
createMemoryHistory | Creates a TanStack Router history whose navigation entries are stored in memory. Initialize it with initialEntries, then pass the history instance to a router. |
createBrowserHistory | Creates the default browser history implementation for TanStack Router. Use its returned history object when you want to provide browser navigation history explicitly. |
mergeForm | |
revalidateLogic | |
getRouteApi | Creates a type-safe RouteApi bound to a route ID. Use it to access route hooks and APIs without importing the route object. |
Hook
| Name | What it does |
|---|---|
useQuery | |
useMutation | useMutation configures and runs server-side writes such as creating, updating, or deleting data. It returns mutation state and commands for triggering, awaiting, or resetting the operation. |
useInfiniteQuery | |
useQueryClient | useQueryClient returns the current React QueryClient. It uses the nearest QueryClientProvider by default, or a supplied QueryClient when one is passed. |
useReactTable | |
useQueries | useQueries runs a dynamic array of TanStack Query queries in parallel. It returns the ordered query results by default, or a single derived value when combine is supplied. |
useSuspenseQuery | useSuspenseQuery fetches query data through React Suspense instead of exposing a disabled or loading state. It returns a useQuery-like result with data guaranteed to be defined. |
useSuspenseInfiniteQuery | |
useSuspenseQueries | useSuspenseQueries runs multiple TanStack Query requests concurrently under React Suspense. It returns their results or an optional combined value, with each query's data guaranteed to be defined. |
useIsFetching | useIsFetching returns how many queries are currently loading or fetching in the background. Optional query filters let you count only selected queries, making it useful for global or scoped loading indicators. |
useIsMutating | useIsMutating returns the number of currently pending mutations. Optional filters can limit the count, making it useful for application-wide loading indicators. |
useMutationState | A React hook for reading state from mutations in the MutationCache. Filter matching mutations and optionally map each one to a custom value. |
usePrefetchQuery | usePrefetchQuery starts a query during render so a descendant behind Suspense can use the data without initiating the first fetch itself. It returns void and skips work when the query already has cached state. |
usePrefetchInfiniteQuery | |
useVirtualizer | useVirtualizer creates a React Virtualizer for an HTML scroll element. It calculates the visible range for large collections while allowing the application to render and style the items. |
useWindowVirtualizer | |
useForm | useForm is a React hook that creates a TanStack Form instance. The returned API manages form state, submission, and fields. |
useField | |
useStore | useStore reads a value from a TanStack Store source, optionally selecting a slice and defining comparison behavior. In React, it is a deprecated alias for useSelector. |
useNavigate | useNavigate returns an imperative navigation function for a TanStack Router application. Use it to change the pathname, search parameters, hash, or location state, especially when navigation is triggered by component logic. |
useParams | useParams returns parsed path parameters from the closest route match and its parents. Options can scope the route or select a derived result. |
useSearch | useSearch returns the current location's search parameters in a TanStack Router React component. Use from for route-specific typing, select for a derived value, and strict: false for a looser shared-schema view. |
useLoaderData | useLoaderData returns loader data from the closest matching route. It supports route-based type narrowing and optional selection of a derived value. |
useRouter | useRouter returns the current TanStack Router instance from context. Use it for imperative router operations in a component. |
useMatch | useMatch returns the RouteMatch for a route in the component tree. It can select a derived value and optionally allow an absent match without throwing. |
useMatches | useMatches returns the router’s complete presented route-match list from any component-tree position. An optional selector can transform that list into a derived result. |
useRouterState | A reactive hook for reading TanStack Router's internal state in a component. An optional selector can reduce the returned value to the specific state needed. |
useBlocker | useBlocker blocks TanStack Router navigation when a condition is met. It can expose the pending transition and controls for continuing or cancelling it. |
useQueryErrorResetBoundary | useQueryErrorResetBoundary exposes a reset function for coordinating TanStack Query errors with an error boundary. It resets errors within the nearest QueryErrorResetBoundary, or globally when no boundary exists. |
useIsRestoring | |
useRouteContext | useRouteContext returns context for a specified current route. Use select to derive and return a narrower value. |
useLinkProps | useLinkProps creates React anchor props from TanStack Router link options and ordinary anchor attributes. Apply the returned props to an anchor to build a navigational link. |
useChildMatches | Returns descendant route matches from the closest match to the leaf-most match, excluding the current match. An optional selector can map those matches to another value. |
useTransform |
Type Alias
| Name | What it does |
|---|---|
ColumnDef | ColumnDef is TanStack Table's union type for describing display, group, and accessor columns. Its generics type the feature set, row data, and cell values. |
RowModel | RowModel is the processed table-row result used by TanStack Table. It provides hierarchical rows, flattened rows, and an ID-keyed row lookup. |
Table | Table<TFeatures, TData> is the TanStack Table instance type. It combines core table behavior with the APIs contributed by the enabled features. |
Row | |
Column | Column is TanStack Table's feature-aware column type. It combines the core column contract with members derived from enabled features and is parameterized by features, row data, and cell-value type. |
Cell | Cell is TanStack Table's feature-aware type for a table cell. It combines the core cell contract with cell-related types supplied by the enabled table features. |
Header | |
HeaderGroup | |
SortingState | |
ColumnFiltersState | |
VisibilityState | VisibilityState is TanStack Table’s map of column IDs to visibility flags. Use it to represent which columns are shown or hidden and to control column-visibility state. |
PaginationState | PaginationState is TanStack Table’s feature-specific type for pagination state. It contains a zero-based page index and the number of rows per page. |
Const
| Name | What it does |
|---|---|
onlineManager | onlineManager is TanStack Query's singleton controller for application connectivity. It reads browser online/offline events by default and supports custom listeners or manual state changes. |
focusManager | focusManager is TanStack Query's singleton focus-state controller. It lets you customize focus events, manually override focus, and inspect the current state. |
notifyManager | notifyManager batches TanStack Query updates and schedules notification callbacks. It supports framework-specific batching, custom notification handling, and configurable scheduling. |
defaultShouldDehydrateQuery | defaultShouldDehydrateQuery is TanStack Query's default predicate for selecting queries during dehydration. It includes only queries with a successful status. |
Pipe
| Name | What it does |
|---|---|
queryKey | queryKey is the array identity for TanStack Query data. It determines cache identity, carries request parameters, and is passed to queryFn through QueryFunctionContext. |
queryFn | queryFn is the data-fetching function for a TanStack Query. It receives QueryFunctionContext and must return defined data or throw; a configured default can provide it when omitted. |
staleTime | staleTime defines how long cached query data stays fresh. Increasing it reduces stale-driven refetches; Infinity waits for manual invalidation, while 'static' prevents even that from triggering a refetch. |
gcTime | gcTime specifies how long unused or inactive TanStack Query cache data stays in memory before garbage collection. It defaults to five minutes, is Infinity during SSR, and can be set to Infinity to disable collection. |
enabled | The enabled option controls whether a query runs automatically. Set it to false to defer fetching, then use refetch for manual execution when needed. |
refetchInterval | refetchInterval makes a query poll on a timer. Use milliseconds for a fixed schedule or a callback for state-dependent polling that can stop by returning false. |
retry | The retry option controls whether failed TanStack Query requests run again. It supports a retry count, disabling or infinite retries, and a callback for error-aware decisions. |
select | |
placeholderData | placeholderData lets a query render with temporary data while the real request runs. Unlike initialData, the temporary value is not persisted in the cache and is marked with isPlaceholderData. |
initialData | initialData prepopulates a query's cache when no cached query exists, allowing the query to render without an initial loading state. The value persists in the cache and is stale by default unless freshness is configured. |
Search across every package and filter by type in your dashboard.
Start learning