npm / @tanstack/react-query
@tanstack/react-query
What changed in @tanstack/react-query 4 to 5, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
78 breaking8 deprecations15 new APIs and options1 performance14 behavior and defaults2 tooling20 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli init@tanstack/react-query 598 changes
Breaking changes 51
The status filter is no longer accepted by QueryClient.isMutating, useIsMutating, or injectIsMutating; these APIs always count mutations with status: 'pending'.
Excludes fetchStatus from filters accepted by QueryClient.isFetching, useIsFetching, and injectIsFetching; these APIs always count queries with fetchStatus: 'fetching'.
The unused experimental_afterQuery hook has been removed.
The unused experimental_beforeQuery hook has been removed.
The promise property has been removed from query results.
Experimental render-time prefetching has been removed.
placeholderData has been removed from suspense infinite queries.
Adds environmentManager.
Renamed to gcTime, which more clearly describes the duration before unused query data is garbage collected.
Removed from QueryClientProvider; share a queryClient instance directly across packages instead.
The custom context prop for hooks was removed; pass a custom queryClient instance to achieve isolation.
The deprecated custom logger support has been removed; logging only had an effect in development mode.
Removed; use shouldDehydrateMutation to control mutation dehydration.
Removed; use shouldDehydrateQuery to control query dehydration.
Error is now the default TypeScript error type instead of unknown; specify a generic for other thrown values.
Removed because object syntax is now the only supported syntax.
Renamed from cacheTime; it controls how long unused query data remains before garbage collection.
Now required for infinite queries; returning null or undefined indicates there is no next page.
Renamed from hashQueryKey; it also hashes mutation keys and can be used in mutation predicates.
Renamed to hashKey.
Renamed to HydrationBoundary.
Replaces Hydrate and hydrates queries, but no longer hydrates mutations.
Required for infinite queries and supplies the first pageParam, avoiding undefined being stored in the query cache.
Removed from useQuery; use structuralSharing to provide equivalent custom data equality behavior.
For queries, newly represents isPending && isFetching; isInitialLoading now has the same meaning and is deprecated.
Replaces isLoading as the derived flag corresponding to the pending status for queries and mutations.
Use this flag in place of isPreviousData when identifying placeholder data.
Removed in favor of isPlaceholderData.
The option is removed in favor of passing the keepPreviousData identity function to placeholderData.
Manual pageParam overrides for fetchNextPage and fetchPreviousPage were removed; getNextPageParam is now required.
Online status starts as true and is updated only from online and offline events, no longer relying on navigator.onLine.
Removed from queries; mutation callbacks are unchanged.
Its function receives previous query data, allowing an identity function to replace keepPreviousData; placeholder data puts the query into success state and leaves dataUpdatedAt at 0.
Hooks can receive a custom queryClient instance directly to provide isolation previously achieved with a custom context.
Now accepts only queryKey; the filters argument is no longer supported.
Now merges all matching registrations instead of returning only the first; order setQueryDefaults registrations from generic to specific.
Now accepts only queryKey; the filters argument is no longer supported.
React 18.0 or later is now required.
Its callback now receives only the query, rather than data and query; access untransformed data through query.state.data.
Removed in favor of maxPages for limiting the pages stored and refetched by infinite queries.
Retries now default to 0 on the server, preventing server-executed queries from retrying.
The loading status is now named pending for queries and mutations.
Can now implement the custom equality behavior previously provided by isDataEqual.
The experimental suspense boolean flag on query hooks has been removed; use the dedicated suspense hooks.
Renamed from useErrorBoundary to describe the option's behavior in a framework-agnostic way.
The minimum supported TypeScript version is now 4.7.
No longer automatically set as the batching function in React and React Native; frameworks can register a custom function with notifyManager.setBatchNotifyFunction.
Renamed to throwOnError.
Removed; use the hydration APIs that remain available.
Query hooks and related APIs now support only the single object signature; positional overloads must be migrated.
Removed; use queryClient.removeQueries to remove a query instead.
Deprecations 8
Renamed to isLoading and deprecated for removal in the next major version.
Deprecated in favor of queryClient.infiniteQuery with staleTime set to 'static'.
Deprecated in favor of queryClient.query with staleTime set to 'static'.
Deprecated in favor of queryClient.infiniteQuery and scheduled for removal in v6.
Deprecated in favor of queryClient.query and scheduled for removal in v6.
Deprecated in favor of queryClient.infiniteQuery; callers can catch its promise to retain prefetch behavior.
Deprecated in favor of queryClient.query; callers can catch its promise to retain prefetch behavior.
Introduced as the replacement for queryClient.fetchQuery; the imperative fetch methods are deprecated and will be removed in v6.
New APIs and options 10
Introduced an experimental fine-grained storage persister.
Limits the number of pages stored in infinite query data and subsequently refetched.
Allows a framework with a custom batching function to register it with TanStack Query.
Infinite queries can prefetch multiple pages by specifying the pages option; by default, only the first page is prefetched.
Introduced as the replacement for queryClient.fetchInfiniteQuery; the imperative fetch methods are deprecated and will be removed in v6.
Function equivalent for controlling whether mutations are dehydrated.
Function equivalent for controlling whether queries are dehydrated.
A typesafe way to create query options is available.
A new combine option is available for combining results from multiple queries.
A stable dedicated suspense hook whose data is never potentially undefined at the type level.
Performance 1
The browserslist was updated to target more modern browsers, producing a smaller and more performant bundle.
Behavior and default changes 8
TData now defaults to InfiniteData<TQueryFnData> to match hook generics.
usePrefetchInfiniteQuery now uses queryClient.infiniteQuery for prefetching.
usePrefetchQuery now uses queryClient.query for prefetching.
Queries and mutations are always dehydrated by default; customize this behavior with shouldDehydrateQuery and shouldDehydrateMutation functions.
Returning null, as well as undefined, indicates there is no previous page.
Class fields and methods are now ECMAScript-private and cannot be accessed from outside at runtime.
Query defaults are now shown set from the less specific key ['todo'] to the more specific key ['todo', 'detail']; this ordering matters when defining defaults.
Window focus refetching now uses visibilitychange exclusively instead of listening to the focus event.
Tooling 2
Codemods no longer copy unnecessary files from the codemods project.
A v5 codemod can migrate positional overloads to the object syntax; use the documented extensions, parser, and transform options for the source files being migrated.
Fixes and other changes 18
Observer options are updated before subscribing, so revealing an <Activity> tree whose query key changed while hidden no longer fetches the previous key.
Corrects the overload selected when initialData may be undefined.
Results are recomputed when filters, selector, or query client change, without waiting for a mutation cache update.
Queries with falsy errors can retry on mount when throwOnError returns false.
Declare @types/react as an optional peer dependency of react-query packages.
useQueries and useSuspenseQueries now throw falsy errors to the error boundary.
Return types can be emitted in declaration files without leaking internal data tag symbols.
Type-only exports no longer emit a runtime import.
Mutation variables become optional when undefined extends TVariables.
Generic type parameters now propagate to the useMutationState select callback.
Unsubscribed useQueries no longer show optimistic fetching.
useQuery return types retain NoInfer.
React Query no longer enters optimistic fetching state when the query is not subscribed.
Suspense queries now skip calling combine, preventing combine from running when queries would suspend.
Resolved an issue involving the excluded build directory.
Maintains error state on reset refetch when initialData is defined.
Allows retryOnMount when throwOnError is a function.
Prevents infinite render loops when useSuspenseQueries has duplicate queryKeys.
@tanstack/react-query 440 changes
Breaking changes 27
The undocumented QueryClient method was removed.
Imperative query-fetching methods now default cancelRefetch to true, cancelling an ongoing fetch and starting a new one; pass false to retain the previous behavior.
The renamed asynchronous storage persister is available from @tanstack/query-async-storage-persister.
The renamed synchronous storage persister is available from @tanstack/query-sync-storage-persister.
The QueryClient method was removed; the functionality remains available through mutationCache.
This method was removed because it did not actually cancel the outgoing request.
Mutation keys must be arrays rather than strings.
Queries and mutations pause by default when there is no network connection; setting networkMode: 'offlineFirst' opts into the previous behavior.
The option no longer accepts 'tracked'; property tracking is the default, and 'all' opts out of smart tracking.
This configuration option has been removed because tracked property notifications are now the default.
setQueryData no longer calls onSuccess; the callback is tied to a request being made.
The persistQueryClient interface formerly named Persistor is now named Persister.
The legacy cancel method on promises is no longer supported; use the AbortController-based query cancellation API.
This unused query method was removed.
Query cache event names changed from queryAdded, queryRemoved, and queryUpdated to added, removed, and updated.
Query keys must be arrays; string keys such as 'todos' must be changed to ['todos'].
The separate hydration entry point was removed; import hydration utilities from @tanstack/react-query.
The React-specific entry point was renamed from react-query/react to @tanstack/react-query/reactjs.
invalidateQueries combines refetchActive and refetchInactive into refetchType, supporting active, inactive, all, or none.
setLogger was removed; configure a logger through the logger field when creating a QueryClient.
The idle status was removed; queries that were idle now report loading status and fetchStatus: 'idle'.
Devtools are installed from a separate package instead of the react-query/devtools entry point.
The react-query package was renamed; install and import @tanstack/react-query instead.
Query filters use type: 'active' | 'inactive' | 'all' instead of the active and inactive boolean flags.
TypeScript v4.1 or greater is now required.
Successful queries may no longer store undefined as their cache value; returning undefined from a queryFn becomes a failed Promise, and the type system disallows it.
The hook now accepts an object with a queries property containing the queries array.
New APIs and options 5
Adds mutationOptions to React Query v4 for configuring mutations.
Adds usePrefetchInfiniteQuery to react-query.
Adds usePrefetchQuery to react-query.
Custom contexts can be specified for hooks and QueryClientProvider to pair them with the correct provider when multiple providers are in the component tree.
Use isInitialLoading to identify disabled queries that have not loaded data, including when deciding whether to show a loading spinner.
Behavior and default changes 6
Mutations can now be garbage collected automatically, with a default cacheTime of five minutes.
Mutation cache events now use the same event types as QueryCacheNotifyEvent.
Package exports support Node's native CommonJS and ESM resolution and restrict imports to officially supported entry points.
Errors are no longer logged to the console in production; development-mode error logging remains.
A functional updater can return undefined to bail out of an update instead of creating or changing a cached entry.
Query properties are tracked by default to improve render optimization.
Fixes and other changes 2
Updated to support React 19 as a peer dependency correctly.
React Query now has first-class support for React 18 and its concurrent features.