- Removed outdated external types dependency
Features & Enhancements
usePaginatedQuery
- A dedicated hook for window-like querying of paginated data or cursor-driven batches of datauseInfiniteQuery
- A dedidated hook for accumulative querying of paginated data or cursor-driven batches of data- Synchronous Query Cache Reads/Writes/Upserts/Deletes
- Improved query key matching for removing and refetching queries
- External subscriptions to query cache updates
- Unlimited query key length support
- Optional Query Variables
onSettled
callback for query and mutation hooksonSuccess
andonError
callbacks for mutations- Better SSR support via
config.initialData
config.initialData
now supports passing an initializer function, similar to React.useState- Query status is now automatically inferred based on
initialData
(success
for non-undefined
intitial data,loading
forundefined
intitial data) - Query objects now supply an
updatedAt
property for making better informed decisions about synchronous cache usage - Overall, less over-fetching out of the box when using multiple instances of a query.
- Added a new
config.refetchOnMount
that defaults totrue
and when set tofalse
will disable additional instances of a query to trigger background refetches. - More reliable suspense support for prefetched queries and background refetching lifecycles
- Support for errorBoundaries out of the box when using Suspense for both queries and mutations
- Added a
globalConfig.queryFnParamsFilter
function that allows filtering the parameters that get sent to the query function.
Breaking Changes
- Query Keys and Query functions
- Query keys in array form are no longer limited to a
[String, Object]
tuple, but can have as many serializable items in them as necessary. - Query functions now receive all query key items as parameters (before they only recieved a single variables object if supplied)
- Query functions can now also receive optional query variables (passed as an optional second variable to
useQuery
) as parameters. They are applied after the query key parameters
- Query keys in array form are no longer limited to a
useQuery
paginated
has been removed in favor of the newusePaginatedQuery
anduseInfiniteQuery
hooks. This includes the following options and methods as well:isFetchingMore
canFetchMore
fetchMore
useMutation
refetchQueries
andupdateQuery
options have been removed in favor ofonSuccess
,onError
andonSettled
+queryCache.refetchQueries
andqueryCache.setQueryData
prefetchQuery
has been removed in favor ofqueryCache.prefetchQuery
refetchQuery
has been removed in favor ofqueryCache.refetchQueries
refetchAllQueries
has been removed in favor ofqueryCache.refetchQueries
updateQuery
has been removed in favor ofqueryCache.setQueryData
clearQueryCache
has been removed in favor ofqueryCache.clear
andqueryCache.removeQueries
- When
initialData
now resolves to any non-undefined
value:status
will be initially set tosuccess
- The query will not automatically refetch on mount
isStale
will initially be set totrue
, and the standard staleTimeout will be applied
- Remove unrelated branch artifacts from dist folder, including types
- Added a new
setConsole
exported function that allows you replace theconsole
interface used to log errors. By default, thewindow.console
object is used.
- Fixed an issue where interval fetching errors would throw repeatedly
- Added the
useMutation.throwOnError
and correspondingqueryConfig.throwOnError
option to configure whether themutate
function rethrows errors encountered in the mutation function - Added the
useMutation.useErrorBoundary
and correspondingqueryConfig.useErrorBoundary
option to configure whether mutation errors should be thrown during the render function and propagated to the nearest error boundary. This option will default to the same value asqueryConfig.suspense
if not defined otherwise - Added a new
reset
function foruseMutation
which will revert the hook's state back to the initialnull
state
- Switched from the fast-async babel plugin to the babel-plugin-transform-async-to-promises. This should offer better compiler/browser support at the expense of 0.1kb
- By default the initial state for
data
is nowundefined
instead ofnull
, allowing for use of default parameters in destructuring. While this may technically be a "breaking" change, it's more of a bug in spirit as it was not intended to be shipped this way. Don't like this? Become a sponsor and demand otherwise ;)
- Fixed an issue where
cancelQueries
was called while not being defined
- Fixed an issue where isDocumentVisible wasn't properly guarded against in all non-web scenarios
- Fixed an issue where query cancellation functions may not have been called
- Added the new
setFocusHandler
utility which allows the overriding of the event that triggers window focusing - Updated the docs to show how to use
setFocusHandler
to avoid iframe events from triggerig window focus
- Fixed an issue where queries would not refresh in the background when using suspense
- Caching is now disabled when React Query is used on the server. It is still possible to seed queries using
initialData
during SSR.
- Fixed an edge case where
useIsLoading
would not update or rerender correctly.
- Added
config.refetchIntervalInBackground
option
- Added
config.initialData
option for SSR
- Fix and issue where
setQueryData
would crash when the query does not exist
- Fix and issue where queries would double fetch when using suspense
- Remove nodent runtime from react-async (shaved off 938 bytes!)
- Better esm bundle configuration
- Add
promise.cancel
support to query promises to support request cancellation APIs - Refetch all on window focus should no longer raise unhandled promise rejections
- Fix issue where
document
was not guarded againts in React Native
- Remove orphaned npm dependencies
- Add
@types/react-query
as a dependency for typescript users
- Fix issue where window focus event would try and register in react-native
- Fix issue where variable hashes could contain arrays or similar number/string pairs
- Fix issue where clearing query cache could lead to out of date query states
- Internal cleanup and refactoring
- Added the
clearQueryCache
API function to clear the query cache
- Fixed an issue where passing
config
toReactQueryConfigProvider
would not update the non-hookdefaultContext
- Fixed an issue where
isLoading
would remaintrue
if a query encountered an error after all retries - Fixed regression where
useIsFetching
stopped working
- Fixed an issue where
useMutation().mutate
would not throw an error when failing
- Fixed an issue where falsey query keys would sometimes still fetch
- Added the
useQuery.onSuccess
callback option - Added the
useQuery.onError
callback option
- Added the
prefetchQuery
method - Improved support for Suspense including fetch-as-you-render patterns
- Undocumented
_useQueries
hook has been removed
- The
useReactQueryConfig
hook is now a provider component calledReactQueryConfigProvider