- Fixed an issue where a falsey query key could not be used in the object syntax
- Fixed an issue where
queryCache.removeQueries
would crash - Fixed an issue where
queryCache.setQueryData
would crash if a functional predicate is used and a query is not found, and thus attempted to be created. - Fixed an issue where
queryCache.setQueryData
would mark a query as fresh but would not schedule a stale timeout.
- Fixed an issue where a nullish query key would result in an error
- Fixed an issue where undefined query keys could possibly result in infinite loops
- Fixed an issue where queries with initial data would not trigger global listeners that that the store had changed
- Fixed an issue where a query would be initialized with wrong state when using falsy initialData
- Fixed an issue where a query would be marked as fetching when using initialData
- Fixed an issue where
useInfiniteQuery
'sfetchMore
method would not work if the query is in the middle of a normal refetch
- Fixed an issue where
usePaginatedQuery
anduseInfiniteQuery
could not be used in suspense mode
- Fixed an issue where useInfiniteQuery could not override the queryFn internally
- Fixed an issue where a function could not be used as the query key
- Fixed an issue where the object syntax for queries could not be used
- Fixed an issue where
queryCache.prefetchQuery
did not resolve the query data if the query was already cached.
- Fixed an issue where some overloaded query arg signatures would not have proper defaults
- Added the
force
option to the privatequery.fetch
function - Added the
force
andthrowOnError
options to therefetch
method to be in line with documentation and expectations of v0.x functionality - Updated documentation to show correct options for
usePaginatedQuery
anduseInfiniteQuery
- Improved documentation around
getFetchMore
and fetch more variables - Fixed an issue where query state was not updated correctly. It is now computed from the query instead of manually tracked.
- Added the ability to configure a query with an object instead of overloaded params
- Fixed an issue where prefetching a query would result in an error
- Fixed an issue where stale queries would not be prefetched properly
- Fixed an issue where a query that had been prefetched before usage in a
useQuery
instance would result in a double fetch
- Fixed an issue where React Query could not be imported properly in dev mode
- Fixed an issue where fresh (non-stale) queries would be refetched when using
queryCache.refetchQueries
or when focusing the window. - Added a
force
option to bothqueryCache.refetchQueries
andqueryCache.prefetchQueries
to restore expected functionality with regards to the issue above, allowing the user to bypass the stale safety of a query and force it to be refetched. - Fixed an issue where
failureCount
would not get reset when a query succeeds
- Memory optimizations when determining currently fetching queries
- Fixed an issue where query retries would not continue firing if the page was unfocused and refocused again
- Fixed an issue where
useIsFetching
would not read properly from the query cache - Fixed an issue where
queryCache.setQueryCache
would not match multiple queries and would not partially match queries - Removed some unused code from the codebase
- Fixed an issue where failed queries with no data could be unintentionally garbage collected immediately
- Fixed an issue where queries with falsey query keys would initialize to
loading
instead ofsuccess
- Fixed an issue where paginated queries, when updated rapidly, would display an unnecessary loading state.
- Fixed a regression where query errors were not thrown properly
- Fixed an issue where the
mutate
function returned fromuseMutation
was not memoized properly
- Silently remove the
query.state.isInactive
boolean. If you somehow relied on this state, then you can still derive it usingconst isInactive = !query.instances.length
- Fixed an issue where the first query rendered on the page would always remount due to a bug in the
useUid
hook - Fixed an issue where queries were still refetching on mount if
manual
wastrue
- Optimized garbage collection for queries that have no data so they will be removed immediately
- Fixed a potential issue where returned promises in try/catch blocks were not always awaited, yet still worked usually.
- Fixed a potential issue where a query function that had already been settled would get it's
cancel
function called.
- Fixed an issue where React Native would try and call
window.addEventListener
- Fixed an issue where
setConsole
was not exported
- 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 dedicated 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