Breaking Changes
Single Object Signature Required
TanStack Query v5 only supports the object format. All previous overloads have been removed.Codemod Available
Run the codemod to automatically migrate:Query Callbacks Removed
onSuccess, onError, and onSettled callbacks have been removed from useQuery and QueryObserver. They remain available on mutations.
See RFC #5279 for the motivation behind this change.
Renamed cacheTime to gcTime
The confusing cacheTime option has been renamed to gcTime (garbage collection time).
Why the rename?
Why the rename?
cacheTime was misleading because it doesn’t control how long data is cached while in use. It only controls how long unused data stays in memory before being garbage collected.Status Changes: loading → pending
The loading status and isLoading flag have been renamed:
TypeScript: Error is Default Error Type
Error type now defaults to Error instead of unknown:
Minimum TypeScript Version: 4.7
TypeScript 4.7 or higher is now required for improved type inference.Renamed useErrorBoundary to throwOnError
remove Method Removed from Query Result
Removed keepPreviousData Option
Replaced with placeholderData identity function:
Infinite Queries Require initialPageParam
Manual Infinite Query Mode Removed
You can no longer passpageParam directly to fetchNextPage. The getNextPageParam value is always used.
null Now Indicates No More Pages
getNextPageParam and getPreviousPageParam can now return null (in addition to undefined) to indicate no more pages:
No Retries on Server by Default
Queries now default toretry: 0 on the server (was 3 in v4):
refetchInterval Callback Simplified
Window Focus Uses visibilitychange Only
The focus event is no longer used. Only visibilitychange is used for detecting window focus.
Network Status Detection Improved
navigator.onLine is no longer used initially. The online status is now determined by online and offline events only.
Custom Context Replaced with Custom QueryClient
refetchPage Removed, Use maxPages
Infinite queries now use maxPages to limit pages:
isDataEqual Removed
Use structuralSharing function instead:
Private Class Fields
TanStack Query now uses ECMAScript private class fields (#field). Previously “private” fields are now truly private at runtime.
Minimum React Version: 18.0
React 18 is now required for theuseSyncExternalStore hook.
Hydrate Component Renamed to HydrationBoundary
Query Defaults Now Merge
queryClient.setQueryDefaults() calls now merge instead of overriding. Order from most generic to most specific:
hashQueryKey Renamed to hashKey
Now works with both query and mutation keys:
New Features
Simplified Optimistic Updates
Usevariables from mutation for optimistic UI:
maxPages for Infinite Queries
Limit pages stored in memory:
Prefetch Multiple Pages
Infinite queries can prefetch multiple pages:combine Option for useQueries
Combine results from multiple queries:
Suspense Hooks
Dedicated suspense hooks with better types:useSuspenseInfiniteQueryuseSuspenseQueries
Experimental Fine-Grained Persister
New experimental persister for better performance. See the createPersister docs.Migration Checklist
1
Update Dependencies
2
Run Codemod
Apply the automated codemod for removing overloads.
3
Replace Callbacks
Move
onSuccess, onError, onSettled from queries to useEffect.4
Update Status Checks
Change
isLoading to isPending where needed.5
Rename Options
cacheTime→gcTimeuseErrorBoundary→throwOnErrorkeepPreviousData→placeholderData: keepPreviousData
6
Update Infinite Queries
Add
initialPageParam to all infinite queries.7
Update Hydration
Rename
Hydrate to HydrationBoundary.8
Test Thoroughly
Test all query and mutation functionality.
Take your time with the migration. v5 brings significant improvements worth the effort!