Skip to content
Source
Sign inSign up
TanStack/query

feat: support skipToken in imperative queries #12681

MergedTkDodomerged 5 commits intoquery-v6 fromrefs/pull/12681/headmerged by TkDodo View on GitHub

Showing 19 changed files with 14 additions and 1 deletion (loading 16).

x
0 of 19 viewed, 19 left
6 additions and 0 deletions.changeset/imperative-query-skip-token.mdAdded
View file
@@ -0,0 +1,6 @@
+---
+'@tanstack/query-core': minor
+'@tanstack/vue-query': minor
+---
+​
+Allow shared options that contain `skipToken` in `queryClient.query` and `queryClient.infiniteQuery`. When `queryFn` is `skipToken`, the call skips fetching and returns existing data or `undefined`. If the options type allows `skipToken`, the result type includes `undefined`.
5 additions and 0 deletionsdocs/framework/react/guides/prefetching.mdModified
View file
@@ -25,6 +25,11 @@
- Return the result of that query
- Throw if it hits any errors
​
+You can pass shared options from `queryOptions` or `infiniteQueryOptions` to
+these methods even when `queryFn` can be `skipToken`. When the options contain
+the token, the call skips the fetch and returns existing data or `undefined`.
+Use `getQueryData` when you need to read the cache directly.
+​
For prefetching you often want to modify these defaults:
​
- Out of the box, `query` uses the default `staleTime` configured for the `queryClient` to determine whether existing data in the cache is fresh or needs to be fetched again
3 additions and 1 deletionpackages/angular-query/src/__tests__/infinite-query-options.test-d.tsModified
View file
@@ -118,7 +118,9 @@
​
const data = await new QueryClient().infiniteQuery(options)
​
- expectTypeOf(data).toEqualTypeOf<InfiniteData<unknown, number>>()