Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

migrating-to-v5.md

529 lines26.5 KB

1---
2id: migrating-to-tanstack-query-5
3title: Migrating to TanStack Query v5
4---
5​
6## Breaking Changes
7​
8v5 is a major version, so there are some breaking changes to be aware of:
9​
10### Supports a single signature, one object
11​
12useQuery and friends used to have many overloads in TypeScript: different ways how the function could be invoked. Not only was this tough to maintain, type wise, it also required a runtime check to see which types the first and the second parameter were, to correctly create options.
13​
14now we only support the object format.
15​
16```tsx
17useQuery(key, fn, options) // [!code --]
18useQuery({ queryKey, queryFn, ...options }) // [!code ++]
19useInfiniteQuery(key, fn, options) // [!code --]
20useInfiniteQuery({ queryKey, queryFn, ...options }) // [!code ++]
21useMutation(fn, options) // [!code --]
22useMutation({ mutationFn, ...options }) // [!code ++]
23useIsFetching(key, filters) // [!code --]
24useIsFetching({ queryKey, ...filters }) // [!code ++]
25useIsMutating(key, filters) // [!code --]
26useIsMutating({ mutationKey, ...filters }) // [!code ++]
27```
28​
29```tsx
30queryClient.isFetching(key, filters) // [!code --]
31queryClient.isFetching({ queryKey, ...filters }) // [!code ++]
32queryClient.ensureQueryData(key, filters) // [!code --]
33queryClient.ensureQueryData({ queryKey, ...filters }) // [!code ++]
34queryClient.getQueriesData(key, filters) // [!code --]
35queryClient.getQueriesData({ queryKey, ...filters }) // [!code ++]
36queryClient.setQueriesData(key, updater, filters, options) // [!code --]
37queryClient.setQueriesData({ queryKey, ...filters }, updater, options) // [!code ++]
38queryClient.removeQueries(key, filters) // [!code --]
39queryClient.removeQueries({ queryKey, ...filters }) // [!code ++]
40queryClient.resetQueries(key, filters, options) // [!code --]
41queryClient.resetQueries({ queryKey, ...filters }, options) // [!code ++]
42queryClient.cancelQueries(key, filters, options) // [!code --]
43queryClient.cancelQueries({ queryKey, ...filters }, options) // [!code ++]
44queryClient.invalidateQueries(key, filters, options) // [!code --]
45queryClient.invalidateQueries({ queryKey, ...filters }, options) // [!code ++]
46queryClient.refetchQueries(key, filters, options) // [!code --]
47queryClient.refetchQueries({ queryKey, ...filters }, options) // [!code ++]
48queryClient.fetchQuery(key, fn, options) // [!code --]
49queryClient.fetchQuery({ queryKey, queryFn, ...options }) // [!code ++]
50queryClient.prefetchQuery(key, fn, options) // [!code --]
51queryClient.prefetchQuery({ queryKey, queryFn, ...options }) // [!code ++]
52queryClient.fetchInfiniteQuery(key, fn, options) // [!code --]
53queryClient.fetchInfiniteQuery({ queryKey, queryFn, ...options }) // [!code ++]
54queryClient.prefetchInfiniteQuery(key, fn, options) // [!code --]
55queryClient.prefetchInfiniteQuery({ queryKey, queryFn, ...options }) // [!code ++]
56```
57​
58```tsx
59queryCache.find(key, filters) // [!code --]
60queryCache.find({ queryKey, ...filters }) // [!code ++]
61queryCache.findAll(key, filters) // [!code --]
62queryCache.findAll({ queryKey, ...filters }) // [!code ++]
63```
64​
65### `queryClient.getQueryData` now accepts queryKey only as an Argument
66​
67`queryClient.getQueryData` argument is changed to accept only a `queryKey`
68​
69```tsx
70queryClient.getQueryData(queryKey, filters) // [!code --]
71queryClient.getQueryData(queryKey) // [!code ++]
72```
73​
74### `queryClient.getQueryState` now accepts queryKey only as an Argument
75​
76`queryClient.getQueryState` argument is changed to accept only a `queryKey`
77​
78```tsx
79queryClient.getQueryState(queryKey, filters) // [!code --]
80queryClient.getQueryState(queryKey) // [!code ++]
81```
82​
83#### Codemod
84​
85To make the remove overloads migration easier, v5 comes with a codemod.
86​
87> The codemod is a best efforts attempt to help you migrate the breaking change. Please review the generated code thoroughly! Also, there are edge cases that cannot be found by the code mod, so please keep an eye on the log output.
88​
89If you want to run it against `.js` or `.jsx` files, please use the command below:
90​
91```
92npx jscodeshift@latest ./path/to/src/ \
93 --extensions=js,jsx \
94 --transform=./node_modules/@tanstack/react-query/build/codemods/src/v5/remove-overloads/remove-overloads.cjs
95```
96​
97If you want to run it against `.ts` or `.tsx` files, please use the command below:
98​
99```
100npx jscodeshift@latest ./path/to/src/ \
101 --extensions=ts,tsx \
102 --parser=tsx \
103 --transform=./node_modules/@tanstack/react-query/build/codemods/src/v5/remove-overloads/remove-overloads.cjs
104```
105​
106Please note in the case of `TypeScript` you need to use `tsx` as the parser; otherwise, the codemod won't be applied properly!
107​
108**Note:** Applying the codemod might break your code formatting, so please don't forget to run `prettier` and/or `eslint` after you've applied the codemod!
109​
110A few notes about how codemod works:
111​
112- Generally, we're looking for the lucky case, when the first parameter is an object expression and contains the "queryKey" or "mutationKey" property (depending on which hook/method call is being transformed). If this is the case, your code already matches the new signature, so the codemod won't touch it. πŸŽ‰
113- If the condition above is not fulfilled, then the codemod will check whether the first parameter is an array expression or an identifier that references an array expression. If this is the case, the codemod will put it into an object expression, then it will be the first parameter.
114- If object parameters can be inferred, the codemod will attempt to copy the already existing properties to the newly created one.
115- If the codemod cannot infer the usage, then it will leave a message on the console. The message contains the file name and the line number of the usage. In this case, you need to do the migration manually.
116- If the transformation results in an error, you will also see a message on the console. This message will notify you something unexpected happened, please do the migration manually.
117​
118### Callbacks on useQuery (and QueryObserver) have been removed
119​
120`onSuccess`, `onError` and `onSettled` have been removed from Queries. They haven't been touched for Mutations. Please see [this RFC](https://github.com/TanStack/query/discussions/5279) for motivations behind this change and what to do instead.
121​
122### The `refetchInterval` callback function only gets `query` passed
123​
124This streamlines how callbacks are invoked (the `refetchOnWindowFocus`, `refetchOnMount` and `refetchOnReconnect` callbacks all only get the query passed as well), and it fixes some typing issues when callbacks get data transformed by `select`.
125​
126```tsx
127- refetchInterval: number | false | ((data: TData | undefined, query: Query) => number | false | undefined) // [!code --]
128+ refetchInterval: number | false | ((query: Query) => number | false | undefined) // [!code ++]
129```
130​
131You can still access data with `query.state.data`, however, it will not be data that has been transformed by `select`. If you need to access the transformed data, you can call the transformation again on `query.state.data`.
132​
133### The `remove` method has been removed from useQuery
134​
135Previously, remove method used to remove the query from the queryCache without informing observers about it. It was best used to remove data imperatively that is no longer needed, e.g. when logging a user out.
136​
137But It doesn't make much sense to do this while a query is still active, because it will just trigger a hard loading state with the next re-render.
138​
139if you still need to remove a query, you can use `queryClient.removeQueries({queryKey: key})`
140​
141```tsx
142const queryClient = useQueryClient()
143const query = useQuery({ queryKey, queryFn })
144​
145query.remove() // [!code --]
146queryClient.removeQueries({ queryKey }) // [!code ++]
147```
148​
149### The minimum required TypeScript version is now 4.7
150​
151Mainly because an important fix was shipped around type inference. Please see this [TypeScript issue](https://github.com/microsoft/TypeScript/issues/43371) for more information.
152​
153### The `isDataEqual` option has been removed from useQuery
154​
155Previously, This function was used to indicate whether to use previous `data` (`true`) or new data (`false`) as a resolved data for the query.
156​
157You can achieve the same functionality by passing a function to `structuralSharing` instead:
158​
159```tsx
160import { replaceEqualDeep } from '@tanstack/react-query'
161​
162- isDataEqual: (oldData, newData) => customCheck(oldData, newData) // [!code --]
163+ structuralSharing: (oldData, newData) => customCheck(oldData, newData) ? oldData : replaceEqualDeep(oldData, newData) // [!code ++]
164```
165​
166### The deprecated custom logger has been removed
167​
168Custom loggers were already deprecated in 4 and have been removed in this version. Logging only had an effect in development mode, where passing a custom logger is not necessary.
169​
170### Supported Browsers
171​
172We have updated our browserslist to produce a more modern, performant and smaller bundle. You can read about the requirements [here](../../installation#requirements).
173​
174### Private class fields and methods
175​
176TanStack Query has always had private fields and methods on classes, but they weren't really private - they were just private in `TypeScript`. We now use [ECMAScript Private class features](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields), which means those fields are now truly private and can't be accessed from the outside at runtime.
177​
178### Rename `cacheTime` to `gcTime`
179​
180Almost everyone gets `cacheTime` wrong. It sounds like "the amount of time that data is cached for", but that is not correct.
181​
182`cacheTime` does nothing as long as a query is still in use. It only kicks in as soon as the query becomes unused. After the time has passed, data will be "garbage collected" to avoid the cache from growing.
183​
184`gc` is referring to "garbage collect" time. It's a bit more technical, but also a quite [well known abbreviation](<https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)>) in computer science.
185​
186```tsx
187const MINUTE = 1000 * 60;
188​
189const queryClient = new QueryClient({
190 defaultOptions: {
191 queries: {
192- cacheTime: 10 * MINUTE, // [!code --]
193+ gcTime: 10 * MINUTE, // [!code ++]
194 },
195 },
196})
197```
198​
199### The `useErrorBoundary` option has been renamed to `throwOnError`
200​
201To make the `useErrorBoundary` option more framework-agnostic and avoid confusion with the established React function prefix "`use`" for hooks and the "ErrorBoundary" component name, it has been renamed to `throwOnError` to more accurately reflect its functionality.
202​
203### TypeScript: `Error` is now the default type for errors instead of `unknown`
204​
205Even though in JavaScript, you can `throw` anything (which makes `unknown` the most correct type), almost always, `Errors` (or subclasses of `Error`) are thrown. This change makes it easier to work with the `error` field in TypeScript for most cases.
206​
207If you want to throw something that isn't an Error, you'll now have to set the generic for yourself:
208​
209```ts
210useQuery<number, string>({
211 queryKey: ['some-query'],
212 queryFn: async () => {
213 if (Math.random() > 0.5) {
214 throw 'some error'
215 }
216 return 42
217 },
218})
219```
220​
221For a way to set a different kind of Error globally, see [the TypeScript Guide](../../typescript.md#registering-a-global-error).
222​
223### eslint `prefer-query-object-syntax` rule is removed
224​
225Since the only supported syntax now is the object syntax, this rule is no longer needed
226​
227### Removed `keepPreviousData` in favor of `placeholderData` identity function
228​
229We have removed the `keepPreviousData` option and `isPreviousData` flag as they were doing mostly the same thing as `placeholderData` and `isPlaceholderData` flag.
230​
231To achieve the same functionality as `keepPreviousData`, we have added previous query `data` as an argument to `placeholderData` which accepts an identity function. Therefore you just need to provide an identity function to `placeholderData` or use the included `keepPreviousData` function from Tanstack Query.
232​
233> A note here is that `useQueries` would not receive `previousData` in the `placeholderData` function as argument. This is due to a dynamic nature of queries passed in the array, which may lead to a different shape of result from placeholder and queryFn.
234​
235```tsx
236import {
237 useQuery,
238+ keepPreviousData // [!code ++]
239} from "@tanstack/react-query";
240​
241const {
242 data,
243- isPreviousData, // [!code --]
244+ isPlaceholderData, // [!code ++]
245} = useQuery({
246 queryKey,
247 queryFn,
248- keepPreviousData: true, // [!code --]
249+ placeholderData: keepPreviousData // [!code ++]
250});
251```
252​
253An identity function, in the context of Tanstack Query, refers to a function that always returns its provided argument (i.e. data) unchanged.
254​
255```ts
256useQuery({
257 queryKey,
258 queryFn,
259 placeholderData: (previousData, previousQuery) => previousData, // identity function with the same behaviour as `keepPreviousData`
260})
261```
262​
263There are some caveats to this change however, which you must be aware of:
264​
265- `placeholderData` will always put you into `success` state, while `keepPreviousData` gave you the status of the previous query. That status could be `error` if we have data fetched successfully and then got a background refetch error. However, the error itself was not shared, so we decided to stick with behavior of `placeholderData`.
266- `keepPreviousData` gave you the `dataUpdatedAt` timestamp of the previous data, while with `placeholderData`, `dataUpdatedAt` will stay at `0`. This might be annoying if you want to show that timestamp continuously on screen. However you might get around it with `useEffect`.
267​
268 ```ts
269 const [updatedAt, setUpdatedAt] = useState(0)
270​
271 const { data, dataUpdatedAt } = useQuery({
272 queryKey: ['projects', page],
273 queryFn: () => fetchProjects(page),
274 })
275​
276 useEffect(() => {
277 if (dataUpdatedAt > updatedAt) {
278 setUpdatedAt(dataUpdatedAt)
279 }
280 }, [dataUpdatedAt])
281 ```
282​
283### Window focus refetching no longer listens to the `focus` event
284​
285The `visibilitychange` event is used exclusively now. This is possible because we only support browsers that support the `visibilitychange` event. This fixes a bunch of issues [as listed here](https://github.com/TanStack/query/pull/4805).
286​
287### Network status no longer relies on the `navigator.onLine` property
288​
289`navigator.onLine` doesn't work well in Chromium based browsers. There are [a lot of issues](https://bugs.chromium.org/p/chromium/issues/list?q=navigator.online) around false negatives, which lead to Queries being wrongfully marked as `offline`.
290​
291To circumvent this, we now always start with `online: true` and only listen to `online` and `offline` events to update the status.
292​
293This should reduce the likelihood of false negatives, however, it might mean false positives for offline apps that load via serviceWorkers, which can work even without an internet connection.
294​
295### Removed custom `context` prop in favor of custom `queryClient` instance
296​
297In v4, we introduced the possibility to pass a custom `context` to all react-query hooks. This allowed for proper isolation when using MicroFrontends.
298​
299However, `context` is a react-only feature. All that `context` does is give us access to the `queryClient`. We could achieve the same isolation by allowing to pass in a custom `queryClient` directly.
300This in turn will enable other frameworks to have the same functionality in a framework-agnostic way.
301​
302```tsx
303import { queryClient } from './my-client'
304​
305const { data } = useQuery(
306 {
307 queryKey: ['users', id],
308 queryFn: () => fetch(...),
309- context: customContext // [!code --]
310 },
311+ queryClient, // [!code ++]
313```
314​
315### Removed `refetchPage` in favor of `maxPages`
316​
317In v4, we introduced the possibility to define the pages to refetch for infinite queries with the `refetchPage` function.
318​
319However, refetching all pages might lead to UI inconsistencies. Also, this option is available on e.g. `queryClient.refetchQueries`, but it only does something for infinite queries, not "normal" queries.
320​
321The v5 includes a new `maxPages` option for infinite queries to limit the number of pages to store in the query data and to refetch. This new feature handles the use cases initially identified for the `refetchPage` page feature without the related issues.
322​
323### New `dehydrate` API
324​
325The options you can pass to `dehydrate` have been simplified. Queries and Mutations are always dehydrated (according to the default function implementation). To change this behaviour, instead of using the removed boolean options `dehydrateMutations` and `dehydrateQueries` you can implement the function equivalents `shouldDehydrateQuery` or `shouldDehydrateMutation` instead. To get the old behaviour of not hydrating queries/mutations at all, pass in `() => false`.
326​
327```tsx
328- dehydrateMutations?: boolean // [!code --]
329- dehydrateQueries?: boolean // [!code --]
330```
331​
332### Infinite queries now need a `initialPageParam`
333​
334Previously, we've passed `undefined` to the `queryFn` as `pageParam`, and you could assign a default value to the `pageParam` parameter in the `queryFn` function signature. This had the drawback of storing `undefined` in the `queryCache`, which is not serializable.
335​
336Instead, you now have to pass an explicit `initialPageParam` to the infinite query options. This will be used as the `pageParam` for the first page:
337​
338```tsx
339useInfiniteQuery({
340 queryKey,
341- queryFn: ({ pageParam = 0 }) => fetchSomething(pageParam), // [!code --]
342+ queryFn: ({ pageParam }) => fetchSomething(pageParam), // [!code ++]
343+ initialPageParam: 0, // [!code ++]
344 getNextPageParam: (lastPage) => lastPage.next,
345})
346```
347​
348### Manual mode for infinite queries has been removed
349​
350Previously, we've allowed to overwrite the `pageParams` that would be returned from `getNextPageParam` or `getPreviousPageParam` by passing a `pageParam` value directly to `fetchNextPage` or `fetchPreviousPage`. This feature didn't work at all with refetches and wasn't widely known or used. This also means that `getNextPageParam` is now required for infinite queries.
351​
352### Returning `null` from `getNextPageParam` or `getPreviousPageParam` now indicates that there is no further page available
353​
354In v4, you needed to explicitly return `undefined` to indicate that there is no further page available. We've widened this check to include `null`.
355​
356### No retries on the server
357​
358On the server, `retry` now defaults to `0` instead of `3`. For prefetching, we have always defaulted to `0` retries, but since queries that have `suspense` enabled can now execute directly on the server as well (since React18), we have to make sure that we don't retry on the server at all.
359​
360### `status: loading` has been changed to `status: pending` and `isLoading` has been changed to `isPending` and `isInitialLoading` has now been renamed to `isLoading`
361​
362The `loading` status has been renamed to `pending`, and similarly the derived `isLoading` flag has been renamed to `isPending`.
363​
364For mutations as well the `status` has been changed from `loading` to `pending` and the `isLoading` flag has been changed to `isPending`.
365​
366Lastly, a new derived `isLoading` flag has been added to the queries that is implemented as `isPending && isFetching`. This means that `isLoading` and `isInitialLoading` have the same thing, but `isInitialLoading` is deprecated now and will be removed in the next major version.
367​
368To understand the reasoning behind this change checkout the [v5 roadmap discussion](https://github.com/TanStack/query/discussions/4252).
369​
370### `hashQueryKey` has been renamed to `hashKey`
371​
372because it also hashes mutation keys and can be used inside the `predicate` functions of `useIsMutating` and `useMutationState`, which gets mutations passed.
373​
374[//]: # 'FrameworkSpecificBreakingChanges'
375​
376### The minimum required React version is now 18.0
377​
378React Query v5 requires React 18.0 or later. This is because we are using the new `useSyncExternalStore` hook, which is only available in React 18.0 and later. Previously, we have been using the shim provided by React.
379​
380### The `contextSharing` prop has been removed from QueryClientProvider
381​
382You could previously use the `contextSharing` property to share the first (and at least one) instance of the query client context across the window. This ensured that if TanStack Query was used across different bundles or microfrontends then they will all use the same instance of the context, regardless of module scoping.
383​
384With the removal of the custom context prop in v5, refer to the section on [Removed custom context prop in favor of custom queryClient instance](#removed-custom-context-prop-in-favor-of-custom-queryclient-instance). If you wish to share the same query client across multiple packages of an application, you can directly pass a shared custom `queryClient` instance.
385​
386### No longer using `unstable_batchedUpdates` as the batching function in React and React Native
387​
388Since the function `unstable_batchedUpdates` is noop in React 18, it will no longer be automatically set as the batching function in `react-query`.
389​
390If your framework supports a custom batching function, you can let TanStack Query know about it by calling `notifyManager.setBatchNotifyFunction`.
391​
392For example, this is how the batch function is set in `solid-query`:
393​
394```ts
395import { notifyManager } from '@tanstack/query-core'
396import { batch } from 'solid-js'
397​
398notifyManager.setBatchNotifyFunction(batch)
399```
400​
401### Hydration API changes
402​
403To better support concurrent features and transitions we've made some changes to the hydration APIs. The `Hydrate` component has been renamed to `HydrationBoundary` and the `useHydrate` hook has been removed.
404​
405The `HydrationBoundary` no longer hydrates mutations, only queries. To hydrate mutations, use the low level `hydrate` API or the `persistQueryClient` plugin.
406​
407Finally, as a technical detail, the timing for when queries are hydrated have changed slightly. New queries are still hydrated in the render phase so that SSR works as usual, but any queries that already exist in the cache are now hydrated in an effect instead (as long as their data is fresher than what is in the cache). If you are hydrating just once at the start of your application as is common, this wont affect you, but if you are using Server Components and pass down fresh data for hydration on a page navigation, you might notice a flash of the old data before the page immediately rerenders.
408​
409This last change is technically a breaking one, and was made so we don't prematurely update content on the _existing_ page before a page transition has been fully committed. No action is required on your part.
410​
411```tsx
412- import { Hydrate } from '@tanstack/react-query' // [!code --]
413+ import { HydrationBoundary } from '@tanstack/react-query' // [!code ++]
414​
415​
416- <Hydrate state={dehydratedState}> // [!code --]
417+ <HydrationBoundary state={dehydratedState}> // [!code ++]
418 <App />
419- </Hydrate> // [!code --]
420+ </HydrationBoundary> // [!code ++]
421```
422​
423### Query defaults changes
424​
425`queryClient.getQueryDefaults` will now merge together all matching registrations instead of returning only the first matching registration.
426​
427As a result, calls to `queryClient.setQueryDefaults` should now be ordered with _increasing_ specificity.
428That is, registrations should be made from the **most generic key** to the **least generic one**.
429​
430For example:
431​
432```ts
433+ queryClient.setQueryDefaults(['todo'], { // [!code ++]
434+ retry: false, // [!code ++]
435+ staleTime: 60_000, // [!code ++]
436+ }) // [!code ++]
437queryClient.setQueryDefaults(['todo', 'detail'], {
438+ retry: true, // [!code --]
439 retryDelay: 1_000,
440 staleTime: 10_000,
441})
442- queryClient.setQueryDefaults(['todo'], { // [!code --]
443- retry: false, // [!code --]
444- staleTime: 60_000, // [!code --]
445- }) // [!code --]
446```
447​
448Note that in this specific example, `retry: true` was added to the `['todo', 'detail']` registration to counteract it now inheriting `retry: false` from the more general registration. The specific changes needed to maintain exact behavior will vary depending on your defaults.
449​
450[//]: # 'FrameworkSpecificBreakingChanges'
451​
452## New Features πŸš€
453​
454v5 also comes with new features:
455​
456### Simplified optimistic updates
457​
458We have a new, simplified way to perform optimistic updates by leveraging the returned `variables` from `useMutation`:
459​
460```tsx
461const queryInfo = useTodos()
462const addTodoMutation = useMutation({
463 mutationFn: (newTodo: string) => axios.post('/api/data', { text: newTodo }),
464 onSettled: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
465})
466​
467if (queryInfo.data) {
468 return (
469 <ul>
470 {queryInfo.data.items.map((todo) => (
471 <li key={todo.id}>{todo.text}</li>
472 ))}
473 {addTodoMutation.isPending && (
474 <li key={String(addTodoMutation.submittedAt)} style={{ opacity: 0.5 }}>
475 {addTodoMutation.variables}
476 </li>
477 )}
478 </ul>
479 )
481```
482​
483Here, we are only changing how the UI looks when the mutation is running instead of writing data directly to the cache. This works best if we only have one place where we need to show the optimistic update. For more details, have a look at the [optimistic updates documentation](../optimistic-updates.md).
484​
485### Limited, Infinite Queries with new maxPages option
486​
487Infinite queries are great when infinite scroll or pagination are needed.
488However, the more pages you fetch, the more memory you consume, and this also slows down the query refetching process as all the pages are sequentially refetched.
489​
490Version 5 has a new `maxPages` option for infinite queries, which allows developers to limit the number of pages that are stored in the query data and subsequently refetched.
491You can adjust the `maxPages` value according to the UX and refetching performance you want to deliver.
492​
493Note that the infinite list must be bi-directional, which requires both `getNextPageParam` and `getPreviousPageParam` to be defined.
494​
495### Infinite Queries can prefetch multiple pages
496​
497Infinite Queries can be prefetched like regular Queries. Per default, only the first page of the Query will be prefetched and will be stored under the given QueryKey. If you want to prefetch more than one page, you can use the `pages` option. Read the [prefetching guide](../prefetching.md) for more information.
498​
499### New `combine` option for `useQueries`
500​
501See the [useQueries docs](../../reference/useQueries.md#combine) for more details.
502​
503### Experimental `fine grained storage persister`
504​
505See the [experimental_createPersister docs](../../plugins/createPersister.md) for more details.
506​
507[//]: # 'FrameworkSpecificNewFeatures'
508​
509### Typesafe way to create Query Options
510​
511See the [TypeScript docs](../../typescript.md#typing-query-options) for more details.
512​
513### new hooks for suspense
514​
515With v5, suspense for data fetching finally becomes "stable". We've added dedicated `useSuspenseQuery`, `useSuspenseInfiniteQuery` and `useSuspenseQueries` hooks. With these hooks, `data` will never be potentially `undefined` on type level:
516​
517```js
518const { data: post } = useSuspenseQuery({
519 // ^? const post: Post
520 queryKey: ['post', postId],
521 queryFn: () => fetchPost(postId),
522})
523```
524​
525The experimental `suspense: boolean` flag on the query hooks has been removed.
526​
527You can read more about them in the [suspense docs](../suspense.md).
528​
529[//]: # 'FrameworkSpecificNewFeatures'