Overview of Changes
Architecture
Scalable and testable cache configuration with separated QueryCache and MutationCache
SSR Support
Improved server-side rendering capabilities
Data Lag
Keep previous data visible while new data loads (replaces usePaginatedQuery)
Bi-directional
Infinite queries can now paginate in both directions
Selectors
Query data selectors for transformation and memoization
useQueries
New hook for variable-length parallel query execution
Breaking Changes
QueryCache Split into QueryClient and Caches
TheQueryCache has been split into QueryClient, QueryCache, and MutationCache:
- Different types of caches
- Multiple clients with different configurations can share the same cache
- Cleaner API focused on general usage
- Easier to test individual components
New QueryClientProvider
Note the change from
defaultConfig to defaultOptions.Default QueryCache Removed
prefetchQuery Changed
Error Boundaries
Cache Methods Renamed
isFetching is Now a Method
useQueryCache → useQueryClient
Query Functions No Longer Receive Split Parameters
Infinite Query Page Params
usePaginatedQuery Removed
Use keepPreviousData option instead:
Infinite Queries are Bi-directional
getFetchMore→getNextPageParamcanFetchMore→hasNextPagefetchMore→fetchNextPageisFetchingMore→isFetchingNextPage- Added
getPreviousPageParam,hasPreviousPage,fetchPreviousPage,isFetchingPreviousPage - Data is now
{ pages: [...], pageParams: [...] }
useMutation Returns Object
mutate No Longer Returns Promise
Query Options Collapsed
enabled Must Be Boolean
initialStale Option Removed
Initial data now respects staleTime:
refetchOnMount Scoped to Component
notifyOnStatusChange Replaced
clear() Renamed to remove()
updatedAt Split
setConsole() Replaced
React Native Auto-Configuration
React Native error logging is now automatic (no need to override console).TypeScript: QueryStatus is Union Type
QueryStatus.Idle→'idle'QueryStatus.Loading→'loading'QueryStatus.Error→'error'QueryStatus.Success→'success'
New Features
Query Data Selectors
notifyOnChangeProps for optimal performance:
useQueries Hook
Mutation Retry & Offline Support
Persist Mutations
Mutations can be persisted and resumed:Query Observers
Watch queries outside React:InfiniteQueryObserverQueriesObserverMutationObserver
Pre-Configure Queries
Pre-Configure Mutations
useIsFetching with Filters
Core Separation
Use React Query core without React:Devtools in Main Package
Migration Checklist
1
Update QueryCache to QueryClient
Replace all
QueryCache instantiation with QueryClient.2
Update Providers
Replace
ReactQueryCacheProvider and ReactQueryConfigProvider with QueryClientProvider.3
Update Hook Names
useQueryCache→useQueryClientusePaginatedQuery→useQuerywithkeepPreviousData
4
Update Infinite Queries
Rename properties and update to use
pages data structure.5
Update Mutations
Change from array to object destructuring.
6
Update Query Function Signatures
Use inline functions or
QueryFunctionContext.7
Update Options
Flatten
config into main options object.8
Update Method Names
getQuery→findgetQueries→findAllclear→remove
9
Test Everything
Thoroughly test all queries, mutations, and cache interactions.
v3 represents a major evolution of React Query with better architecture, improved TypeScript support, and many powerful new features.