@tanstack/solid-query 5.104.5 → 5.105.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/dev.cjs +15 -30
- package/build/dev.js +15 -30
- package/build/index.cjs +1 -1
- package/build/index.d.cts +68 -97
- package/build/index.d.cts.map +1 -1
- package/build/index.d.ts +68 -97
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/package.json +2 -2
- package/src/infiniteQueryOptions.ts +16 -10
- package/src/queryOptions.ts +19 -11
- package/src/useInfiniteQuery.ts +3 -3
- package/src/useIsFetching.ts +1 -1
- package/src/useQuery.ts +50 -50
package/src/queryOptions.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DefaultError,
|
|
3
|
+
InitialDataFunction,
|
|
4
|
+
NonUndefinedGuard,
|
|
3
5
|
QueryKey,
|
|
4
6
|
QueryKeyWithDataTag,
|
|
5
7
|
} from '@tanstack/query-core'
|
|
@@ -7,10 +9,11 @@ import type { QueryOptions } from './types'
|
|
|
7
9
|
import type { Accessor } from 'solid-js'
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
|
-
* The options accepted by the `queryOptions` overload selected when
|
|
11
|
-
* `undefined
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* The options accepted by the `queryOptions` overload selected when `initialData` is omitted, may be
|
|
13
|
+
* `undefined`, or is a function that may return `undefined` — `data` may be `undefined` while the query is
|
|
14
|
+
* `pending`. `queryOptions` itself accepts and returns a plain object (its parameter type is
|
|
15
|
+
* `ReturnType<UndefinedInitialDataOptions<...>>`, i.e. this `Accessor` called); Solid's reactivity applies
|
|
16
|
+
* where the result is consumed instead, e.g. `useQuery(() => options)`.
|
|
14
17
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
15
18
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
16
19
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -23,13 +26,16 @@ export type UndefinedInitialDataOptions<
|
|
|
23
26
|
TQueryKey extends QueryKey = QueryKey,
|
|
24
27
|
> = Accessor<
|
|
25
28
|
QueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
26
|
-
initialData?:
|
|
29
|
+
initialData?:
|
|
30
|
+
| undefined
|
|
31
|
+
| InitialDataFunction<NonUndefinedGuard<TQueryFnData>>
|
|
32
|
+
| NonUndefinedGuard<TQueryFnData>
|
|
27
33
|
}
|
|
28
34
|
>
|
|
29
35
|
|
|
30
36
|
/**
|
|
31
|
-
* The options accepted by the `queryOptions` overload selected when `initialData` is
|
|
32
|
-
* `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
37
|
+
* The options accepted by the `queryOptions` overload selected when `initialData` is known to be defined —
|
|
38
|
+
* `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
33
39
|
* @template TQueryFnData - The type your `queryFn` resolves to.
|
|
34
40
|
* @template TError - The type of errors your `queryFn` may throw.
|
|
35
41
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
@@ -42,7 +48,9 @@ export type DefinedInitialDataOptions<
|
|
|
42
48
|
TQueryKey extends QueryKey = QueryKey,
|
|
43
49
|
> = Accessor<
|
|
44
50
|
QueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
45
|
-
initialData:
|
|
51
|
+
initialData:
|
|
52
|
+
| NonUndefinedGuard<TQueryFnData>
|
|
53
|
+
| (() => NonUndefinedGuard<TQueryFnData>)
|
|
46
54
|
}
|
|
47
55
|
>
|
|
48
56
|
|
|
@@ -51,9 +59,9 @@ export type DefinedInitialDataOptions<
|
|
|
51
59
|
* be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and
|
|
52
60
|
* is the query key to generate options for.
|
|
53
61
|
*
|
|
54
|
-
* This overload is selected when `initialData` is
|
|
55
|
-
* a `select` changes `TData` to include `undefined`).
|
|
56
|
-
* @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData`
|
|
62
|
+
* This overload is selected when `initialData` is known to be defined, so the resulting `data` is never
|
|
63
|
+
* `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
64
|
+
* @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `useQuery`, with `initialData` known to be defined.
|
|
57
65
|
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
58
66
|
* @see {@link useQuery} to run a query with these options.
|
|
59
67
|
* @example
|
package/src/useInfiniteQuery.ts
CHANGED
|
@@ -23,9 +23,9 @@ import type {
|
|
|
23
23
|
* The options for `useInfiniteQuery` are identical to `useQuery`, with the addition of
|
|
24
24
|
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`.
|
|
25
25
|
*
|
|
26
|
-
* This overload is selected when `initialData` is
|
|
27
|
-
* @param options - An accessor returning the {@link DefinedInitialDataInfiniteOptions} to use — everything
|
|
28
|
-
* can pass to `useInfiniteQuery`, with `initialData`
|
|
26
|
+
* This overload is selected when `initialData` is known to be defined.
|
|
27
|
+
* @param options - An accessor returning the {@link DefinedInitialDataInfiniteOptions} to use — everything
|
|
28
|
+
* you can pass to `useInfiniteQuery`, with `initialData` known to be defined.
|
|
29
29
|
* @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
30
30
|
* will be used.
|
|
31
31
|
* @returns The same properties as `useQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
|
package/src/useIsFetching.ts
CHANGED
|
@@ -25,7 +25,7 @@ import type { Accessor } from 'solid-js'
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
export function useIsFetching(
|
|
28
|
-
filters?: Accessor<QueryFilters
|
|
28
|
+
filters?: Accessor<Omit<QueryFilters, 'fetchStatus'>>,
|
|
29
29
|
queryClient?: Accessor<QueryClient>,
|
|
30
30
|
): Accessor<number> {
|
|
31
31
|
const resolveClient = useQueryClientResolver(queryClient)
|
package/src/useQuery.ts
CHANGED
|
@@ -14,6 +14,56 @@ import type {
|
|
|
14
14
|
UndefinedInitialDataOptions,
|
|
15
15
|
} from './queryOptions'
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
19
|
+
* The query runs when the options call for it — `enabled: false` skips the initial fetch.
|
|
20
|
+
*
|
|
21
|
+
* This overload is selected when `initialData` is known to be defined, so the resulting `data` is never
|
|
22
|
+
* `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
23
|
+
* @param options - An accessor returning the {@link DefinedInitialDataOptions} to use — everything you can
|
|
24
|
+
* pass to `useQuery`, with `initialData` known to be defined.
|
|
25
|
+
* @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
26
|
+
* will be used.
|
|
27
|
+
* @returns The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a
|
|
28
|
+
* fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's
|
|
29
|
+
* type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for
|
|
30
|
+
* convenience.
|
|
31
|
+
* @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* import { For } from 'solid-js'
|
|
35
|
+
* import { useQuery } from '@tanstack/solid-query'
|
|
36
|
+
*
|
|
37
|
+
* function Posts() {
|
|
38
|
+
* // `postsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the
|
|
39
|
+
* // list stays visible alongside the error.
|
|
40
|
+
* const postsQuery = useQuery(() => ({
|
|
41
|
+
* queryKey: ['posts'],
|
|
42
|
+
* queryFn: fetchPosts,
|
|
43
|
+
* initialData: [],
|
|
44
|
+
* }))
|
|
45
|
+
*
|
|
46
|
+
* return (
|
|
47
|
+
* <div>
|
|
48
|
+
* {postsQuery.isError ? <span>Error: {postsQuery.error.message}</span> : null}
|
|
49
|
+
* <ul>
|
|
50
|
+
* <For each={postsQuery.data}>{(post) => <li>{post.title}</li>}</For>
|
|
51
|
+
* </ul>
|
|
52
|
+
* </div>
|
|
53
|
+
* )
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function useQuery<
|
|
58
|
+
TQueryFnData = unknown,
|
|
59
|
+
TError = DefaultError,
|
|
60
|
+
TData = TQueryFnData,
|
|
61
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
62
|
+
>(
|
|
63
|
+
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
64
|
+
queryClient?: () => QueryClient,
|
|
65
|
+
): DefinedUseQueryResult<TData, TError>
|
|
66
|
+
|
|
17
67
|
/**
|
|
18
68
|
* Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
19
69
|
* The query runs when the options call for it — `enabled: false` skips the initial fetch.
|
|
@@ -184,56 +234,6 @@ export function useQuery<
|
|
|
184
234
|
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
185
235
|
queryClient?: () => QueryClient,
|
|
186
236
|
): UseQueryResult<TData, TError>
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
190
|
-
* The query runs when the options call for it — `enabled: false` skips the initial fetch.
|
|
191
|
-
*
|
|
192
|
-
* This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
|
|
193
|
-
* a `select` changes `TData` to include `undefined`).
|
|
194
|
-
* @param options - An accessor returning the {@link DefinedInitialDataOptions} to use — everything you can
|
|
195
|
-
* pass to `useQuery`, with `initialData` set.
|
|
196
|
-
* @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context
|
|
197
|
-
* will be used.
|
|
198
|
-
* @returns The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a
|
|
199
|
-
* fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's
|
|
200
|
-
* type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for
|
|
201
|
-
* convenience.
|
|
202
|
-
* @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`.
|
|
203
|
-
* @example
|
|
204
|
-
* ```tsx
|
|
205
|
-
* import { For } from 'solid-js'
|
|
206
|
-
* import { useQuery } from '@tanstack/solid-query'
|
|
207
|
-
*
|
|
208
|
-
* function Posts() {
|
|
209
|
-
* // `postsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the
|
|
210
|
-
* // list stays visible alongside the error.
|
|
211
|
-
* const postsQuery = useQuery(() => ({
|
|
212
|
-
* queryKey: ['posts'],
|
|
213
|
-
* queryFn: fetchPosts,
|
|
214
|
-
* initialData: [],
|
|
215
|
-
* }))
|
|
216
|
-
*
|
|
217
|
-
* return (
|
|
218
|
-
* <div>
|
|
219
|
-
* {postsQuery.isError ? <span>Error: {postsQuery.error.message}</span> : null}
|
|
220
|
-
* <ul>
|
|
221
|
-
* <For each={postsQuery.data}>{(post) => <li>{post.title}</li>}</For>
|
|
222
|
-
* </ul>
|
|
223
|
-
* </div>
|
|
224
|
-
* )
|
|
225
|
-
* }
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
export function useQuery<
|
|
229
|
-
TQueryFnData = unknown,
|
|
230
|
-
TError = DefaultError,
|
|
231
|
-
TData = TQueryFnData,
|
|
232
|
-
TQueryKey extends QueryKey = QueryKey,
|
|
233
|
-
>(
|
|
234
|
-
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
235
|
-
queryClient?: () => QueryClient,
|
|
236
|
-
): DefinedUseQueryResult<TData, TError>
|
|
237
237
|
export function useQuery<
|
|
238
238
|
TQueryFnData,
|
|
239
239
|
TError = DefaultError,
|