
With version 3.22.0, hydration utilities moved into the react-query core. With v3, you could still use the old exports from react-query/hydration, but these exports have been removed with v4.
- import { dehydrate, hydrate, useHydrate, Hydrate } from 'react-query/hydration'+ import { dehydrate, hydrate, useHydrate, Hydrate } from 'react-query'
cancelRefetchThe cancelRefetch can be passed to all functions that imperatively fetch a query, namely:
queryClient.refetchQueriesqueryClient.invalidateQueriesqueryClient.resetQueriesrefetch returned from useQueryfetchNetPage and fetchPreviousPage returned from useInfiniteQueryExcept for fetchNetxPage and fetchPreviousPage, this flag was defaulting to false, which was inconsistent and potentially troublesome: Calling refetchQueries or invalidateQueries after a mutation might not yield the latest result if a previous slow fetch was already ongoing, because this refetch would have been skipped.
We believe that if a query is actively refetched by some code you write, it should, per default, re-start the fetch.
That is why this flag now defaults to true for all methods mentioned above. It also means that if you call refetchQueries twice in a row, without awaiting it, it will now cancel the first fetch and re-start it with the second one:
queryClient.refetchQueries({ queryKey: ['todos'] })// this will abort the previous refetch and start a new fetchqueryClient.refetchQueries({ queryKey: ['todos'] })
You can opt-out of this behaviour by explicitly passing cancelRefetch:false:
queryClient.refetchQueries({ queryKey: ['todos'] })// this will not abort the previous refetch - it will just be ignoredqueryClient.refetchQueries({ queryKey: ['todos'] }, { cancelRefetch: false })
Note: There is no change in behaviour for automatically triggered fetches, e.g. because a query mounts or because of a window focus refetch.
The latest TanStack news, articles, and resources, sent to your inbox.