diff --git a/.changeset/solid-queryoptions-initialdata-overload.md b/.changeset/solid-queryoptions-initialdata-overload.md new file mode 100644 index 00000000000..4091a49dd70 --- /dev/null +++ b/.changeset/solid-queryoptions-initialdata-overload.md @@ -0,0 +1,5 @@ +--- +'@tanstack/solid-query': patch +--- + +fix(solid-query/{queryOptions,useQuery}): correct the overload selected for 'initialData' diff --git a/docs/framework/solid/reference/functions/queryOptions.md b/docs/framework/solid/reference/functions/queryOptions.md index f5989618383..69c69a7b42f 100644 --- a/docs/framework/solid/reference/functions/queryOptions.md +++ b/docs/framework/solid/reference/functions/queryOptions.md @@ -27,7 +27,7 @@ See also: [Parameters](#parameters-summary) · [Returns](#returns-summary) function queryOptions(options: QueryOptions & object): ReturnType> & QueryKeyWithDataTag; ``` -Defined in: [packages/solid-query/src/queryOptions.ts:86](https://github.com/TanStack/query/blob/main/packages/solid-query/src/queryOptions.ts#L86) +Defined in: [packages/solid-query/src/queryOptions.ts:93](https://github.com/TanStack/query/blob/main/packages/solid-query/src/queryOptions.ts#L93) You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and @@ -108,7 +108,7 @@ function Posts() { function queryOptions(options: QueryOptions & object): ReturnType> & QueryKeyWithDataTag; ``` -Defined in: [packages/solid-query/src/queryOptions.ts:134](https://github.com/TanStack/query/blob/main/packages/solid-query/src/queryOptions.ts#L134) +Defined in: [packages/solid-query/src/queryOptions.ts:141](https://github.com/TanStack/query/blob/main/packages/solid-query/src/queryOptions.ts#L141) You can generally pass everything to `queryOptions` that you can also pass to `useQuery`. These options can be shared across hooks and imperative APIs such as `queryClient.query`. `options.queryKey` is required and diff --git a/docs/framework/solid/reference/functions/useQuery.md b/docs/framework/solid/reference/functions/useQuery.md index 9adb7e23d3a..3aaeb7fc5c7 100644 --- a/docs/framework/solid/reference/functions/useQuery.md +++ b/docs/framework/solid/reference/functions/useQuery.md @@ -10,12 +10,12 @@ redirect_from: ## Overview ```ts -function useQuery(options: UndefinedInitialDataOptions, queryClient?: () => QueryClient): UseQueryResult; function useQuery(options: DefinedInitialDataOptions, queryClient?: () => QueryClient): DefinedUseQueryResult; +function useQuery(options: UndefinedInitialDataOptions, queryClient?: () => QueryClient): UseQueryResult; ``` -- [`UndefinedInitialDataOptions` → `UseQueryResult`](#call-signature-1): Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. The query runs when the options call for it — `enabled: false` skips the initial fetch. -- [`DefinedInitialDataOptions` → `DefinedUseQueryResult`](#call-signature-2): Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. The query runs when the options call for it — `enabled: false` skips the initial fetch. +- [`DefinedInitialDataOptions` → `DefinedUseQueryResult`](#call-signature-1): Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. The query runs when the options call for it — `enabled: false` skips the initial fetch. +- [`UndefinedInitialDataOptions` → `UseQueryResult`](#call-signature-2): Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. The query runs when the options call for it — `enabled: false` skips the initial fetch. See also: [Parameters](#parameters-summary) · [Returns](#returns-summary) @@ -23,11 +23,100 @@ See also: [Parameters](#parameters-summary) · [Returns](#returns-summary) ## Call Signature +```ts +function useQuery(options: DefinedInitialDataOptions, queryClient?: () => QueryClient): DefinedUseQueryResult; +``` + +Defined in: [packages/solid-query/src/useQuery.ts:57](https://github.com/TanStack/query/blob/main/packages/solid-query/src/useQuery.ts#L57) + +Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. +The query runs when the options call for it — `enabled: false` skips the initial fetch. + +This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless +a `select` changes `TData` to include `undefined`). + +### Type Parameters + +#### TQueryFnData + +`TQueryFnData` = `unknown` + +#### TError + +`TError` = `Error` + +#### TData + +`TData` = `TQueryFnData` + +#### TQueryKey + +`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[] + +### Parameters + +#### options + +[`DefinedInitialDataOptions`](../type-aliases/DefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> + +An accessor returning the [DefinedInitialDataOptions](../type-aliases/DefinedInitialDataOptions.md) to use — everything you can +pass to `useQuery`, with `initialData` set. + +#### queryClient? + +() => [`QueryClient`](../classes/QueryClient.md) + +An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context +will be used. + +### Returns + +[`DefinedUseQueryResult`](../type-aliases/DefinedUseQueryResult.md)\<`TData`, `TError`\> + +The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a +fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's +type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for +convenience. + +### See + +[queryOptions](queryOptions.md) to share these options between `useQuery` and imperative APIs like `queryClient.query`. + +### Example + +```tsx +import { For } from 'solid-js' +import { useQuery } from '@tanstack/solid-query' + +function Posts() { + // `postsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the + // list stays visible alongside the error. + const postsQuery = useQuery(() => ({ + queryKey: ['posts'], + queryFn: fetchPosts, + initialData: [], + })) + + return ( +
+ {postsQuery.isError ? Error: {postsQuery.error.message} : null} +
    + {(post) =>
  • {post.title}
  • }
    +
+
+ ) +} +``` + + + +## Call Signature + ```ts function useQuery(options: UndefinedInitialDataOptions, queryClient?: () => QueryClient): UseQueryResult; ``` -Defined in: [packages/solid-query/src/useQuery.ts:178](https://github.com/TanStack/query/blob/main/packages/solid-query/src/useQuery.ts#L178) +Defined in: [packages/solid-query/src/useQuery.ts:228](https://github.com/TanStack/query/blob/main/packages/solid-query/src/useQuery.ts#L228) Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. The query runs when the options call for it — `enabled: false` skips the initial fetch. @@ -229,105 +318,16 @@ function Posts() { } ``` - - -## Call Signature - -```ts -function useQuery(options: DefinedInitialDataOptions, queryClient?: () => QueryClient): DefinedUseQueryResult; -``` - -Defined in: [packages/solid-query/src/useQuery.ts:228](https://github.com/TanStack/query/blob/main/packages/solid-query/src/useQuery.ts#L228) - -Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. -The query runs when the options call for it — `enabled: false` skips the initial fetch. - -This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless -a `select` changes `TData` to include `undefined`). - -### Type Parameters - -#### TQueryFnData - -`TQueryFnData` = `unknown` - -#### TError - -`TError` = `Error` - -#### TData - -`TData` = `TQueryFnData` - -#### TQueryKey - -`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[] - -### Parameters - -#### options - -[`DefinedInitialDataOptions`](../type-aliases/DefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> - -An accessor returning the [DefinedInitialDataOptions](../type-aliases/DefinedInitialDataOptions.md) to use — everything you can -pass to `useQuery`, with `initialData` set. - -#### queryClient? - -() => [`QueryClient`](../classes/QueryClient.md) - -An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context -will be used. - -### Returns - -[`DefinedUseQueryResult`](../type-aliases/DefinedUseQueryResult.md)\<`TData`, `TError`\> - -The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a -fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's -type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for -convenience. - -### See - -[queryOptions](queryOptions.md) to share these options between `useQuery` and imperative APIs like `queryClient.query`. - -### Example - -```tsx -import { For } from 'solid-js' -import { useQuery } from '@tanstack/solid-query' - -function Posts() { - // `postsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the - // list stays visible alongside the error. - const postsQuery = useQuery(() => ({ - queryKey: ['posts'], - queryFn: fetchPosts, - initialData: [], - })) - - return ( -
- {postsQuery.isError ? Error: {postsQuery.error.message} : null} -
    - {(post) =>
  • {post.title}
  • }
    -
-
- ) -} -``` - ## Parameters ### options -[`DefinedInitialDataOptions`](../type-aliases/DefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> +[`UndefinedInitialDataOptions`](../type-aliases/UndefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> -An accessor returning the [DefinedInitialDataOptions](../type-aliases/DefinedInitialDataOptions.md) to use — everything you can -pass to `useQuery`, with `initialData` set. +An accessor returning the [UndefinedInitialDataOptions](../type-aliases/UndefinedInitialDataOptions.md) to use — everything you can +pass to `useQuery`. @@ -346,12 +346,11 @@ will be used. ## Returns -[`DefinedUseQueryResult`](../type-aliases/DefinedUseQueryResult.md)\<`TData`, `TError`\> +[`UseQueryResult`](../type-aliases/UseQueryResult.md)\<`TData`, `TError`\> -The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a -fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's -type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for -convenience. +The current query result, as a Solid store. `status` is `pending` if there is no cached data to +display, `error` if the last fetch attempt failed, or `success` if the query has data to display. +`isPending`/`isSuccess`/`isError` are derived booleans for convenience. diff --git a/docs/framework/solid/reference/type-aliases/DefinedInitialDataOptions.md b/docs/framework/solid/reference/type-aliases/DefinedInitialDataOptions.md index e771bc53daf..184375ba831 100644 --- a/docs/framework/solid/reference/type-aliases/DefinedInitialDataOptions.md +++ b/docs/framework/solid/reference/type-aliases/DefinedInitialDataOptions.md @@ -9,7 +9,7 @@ title: DefinedInitialDataOptions type DefinedInitialDataOptions = Accessor & object>; ``` -Defined in: [packages/solid-query/src/queryOptions.ts:38](https://github.com/TanStack/query/blob/main/packages/solid-query/src/queryOptions.ts#L38) +Defined in: [packages/solid-query/src/queryOptions.ts:43](https://github.com/TanStack/query/blob/main/packages/solid-query/src/queryOptions.ts#L43) The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never `undefined` (unless a `select` changes `TData` to include `undefined`). diff --git a/docs/framework/solid/reference/type-aliases/UndefinedInitialDataOptions.md b/docs/framework/solid/reference/type-aliases/UndefinedInitialDataOptions.md index 2f2aa8af511..6b69a3a19b6 100644 --- a/docs/framework/solid/reference/type-aliases/UndefinedInitialDataOptions.md +++ b/docs/framework/solid/reference/type-aliases/UndefinedInitialDataOptions.md @@ -9,7 +9,7 @@ title: UndefinedInitialDataOptions type UndefinedInitialDataOptions = Accessor & object>; ``` -Defined in: [packages/solid-query/src/queryOptions.ts:19](https://github.com/TanStack/query/blob/main/packages/solid-query/src/queryOptions.ts#L19) +Defined in: [packages/solid-query/src/queryOptions.ts:21](https://github.com/TanStack/query/blob/main/packages/solid-query/src/queryOptions.ts#L21) The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be `undefined` while the query is `pending`. `queryOptions` itself accepts and returns a plain object (its diff --git a/docs/framework/solid/reference/variables/createQuery.md b/docs/framework/solid/reference/variables/createQuery.md index ca4c48639c8..a20a2a84df1 100644 --- a/docs/framework/solid/reference/variables/createQuery.md +++ b/docs/framework/solid/reference/variables/createQuery.md @@ -7,8 +7,8 @@ title: createQuery ```ts const createQuery: { - (options: UndefinedInitialDataOptions, queryClient?: () => QueryClient): UseQueryResult; (options: DefinedInitialDataOptions, queryClient?: () => QueryClient): DefinedUseQueryResult; + (options: UndefinedInitialDataOptions, queryClient?: () => QueryClient): UseQueryResult; } = useQuery; ``` @@ -16,6 +16,91 @@ Defined in: [packages/solid-query/src/index.ts:57](https://github.com/TanStack/q ## Call Signature +```ts +(options: DefinedInitialDataOptions, queryClient?: () => QueryClient): DefinedUseQueryResult; +``` + +Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. +The query runs when the options call for it — `enabled: false` skips the initial fetch. + +This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless +a `select` changes `TData` to include `undefined`). + +### Type Parameters + +#### TQueryFnData + +`TQueryFnData` = `unknown` + +#### TError + +`TError` = `Error` + +#### TData + +`TData` = `TQueryFnData` + +#### TQueryKey + +`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[] + +### Parameters + +#### options + +[`DefinedInitialDataOptions`](../type-aliases/DefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> + +An accessor returning the [DefinedInitialDataOptions](../type-aliases/DefinedInitialDataOptions.md) to use — everything you can +pass to `useQuery`, with `initialData` set. + +#### queryClient? + +() => [`QueryClient`](../classes/QueryClient.md) + +An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context +will be used. + +### Returns + +[`DefinedUseQueryResult`](../type-aliases/DefinedUseQueryResult.md)\<`TData`, `TError`\> + +The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a +fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's +type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for +convenience. + +### See + +[queryOptions](../functions/queryOptions.md) to share these options between `useQuery` and imperative APIs like `queryClient.query`. + +### Example + +```tsx +import { For } from 'solid-js' +import { useQuery } from '@tanstack/solid-query' + +function Posts() { + // `postsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the + // list stays visible alongside the error. + const postsQuery = useQuery(() => ({ + queryKey: ['posts'], + queryFn: fetchPosts, + initialData: [], + })) + + return ( +
+ {postsQuery.isError ? Error: {postsQuery.error.message} : null} +
    + {(post) =>
  • {post.title}
  • }
    +
+
+ ) +} +``` + +## Call Signature + ```ts (options: UndefinedInitialDataOptions, queryClient?: () => QueryClient): UseQueryResult; ``` @@ -219,88 +304,3 @@ function Posts() { ) } ``` - -## Call Signature - -```ts -(options: DefinedInitialDataOptions, queryClient?: () => QueryClient): DefinedUseQueryResult; -``` - -Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. -The query runs when the options call for it — `enabled: false` skips the initial fetch. - -This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless -a `select` changes `TData` to include `undefined`). - -### Type Parameters - -#### TQueryFnData - -`TQueryFnData` = `unknown` - -#### TError - -`TError` = `Error` - -#### TData - -`TData` = `TQueryFnData` - -#### TQueryKey - -`TQueryKey` *extends* readonly `unknown`[] = readonly `unknown`[] - -### Parameters - -#### options - -[`DefinedInitialDataOptions`](../type-aliases/DefinedInitialDataOptions.md)\<`TQueryFnData`, `TError`, `TData`, `TQueryKey`\> - -An accessor returning the [DefinedInitialDataOptions](../type-aliases/DefinedInitialDataOptions.md) to use — everything you can -pass to `useQuery`, with `initialData` set. - -#### queryClient? - -() => [`QueryClient`](../classes/QueryClient.md) - -An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context -will be used. - -### Returns - -[`DefinedUseQueryResult`](../type-aliases/DefinedUseQueryResult.md)\<`TData`, `TError`\> - -The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a -fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's -type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for -convenience. - -### See - -[queryOptions](../functions/queryOptions.md) to share these options between `useQuery` and imperative APIs like `queryClient.query`. - -### Example - -```tsx -import { For } from 'solid-js' -import { useQuery } from '@tanstack/solid-query' - -function Posts() { - // `postsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the - // list stays visible alongside the error. - const postsQuery = useQuery(() => ({ - queryKey: ['posts'], - queryFn: fetchPosts, - initialData: [], - })) - - return ( -
- {postsQuery.isError ? Error: {postsQuery.error.message} : null} -
    - {(post) =>
  • {post.title}
  • }
    -
-
- ) -} -``` diff --git a/packages/solid-query/src/__tests__/queryOptions.test-d.tsx b/packages/solid-query/src/__tests__/queryOptions.test-d.tsx index 56eac081c53..6483ef2d37e 100644 --- a/packages/solid-query/src/__tests__/queryOptions.test-d.tsx +++ b/packages/solid-query/src/__tests__/queryOptions.test-d.tsx @@ -112,6 +112,18 @@ describe('queryOptions', () => { expectTypeOf(tagged[dataTagSymbol]).toEqualTypeOf() }) + it('should keep data possibly undefined and tag the queryKey with the result type of the QueryFn when initialData may be undefined', () => { + const options = queryOptions({ + queryKey: createKey(), + queryFn: () => Promise.resolve(5), + initialData: Math.random() > 0.5 ? 5 : undefined, + }) + const { data } = useQuery(() => options) + + expectTypeOf(data).toEqualTypeOf() + expectTypeOf(options.queryKey[dataTagSymbol]).toEqualTypeOf() + }) + it('should tag the queryKey even if no promise is returned', () => { const { queryKey: tagged } = queryOptions({ queryKey: createKey(), diff --git a/packages/solid-query/src/queryOptions.ts b/packages/solid-query/src/queryOptions.ts index 0d9c68c8bce..2211cfe7a5b 100644 --- a/packages/solid-query/src/queryOptions.ts +++ b/packages/solid-query/src/queryOptions.ts @@ -1,5 +1,7 @@ import type { DefaultError, + InitialDataFunction, + NonUndefinedGuard, QueryKey, QueryKeyWithDataTag, } from '@tanstack/query-core' @@ -23,7 +25,10 @@ export type UndefinedInitialDataOptions< TQueryKey extends QueryKey = QueryKey, > = Accessor< QueryOptions & { - initialData?: undefined + initialData?: + | undefined + | InitialDataFunction> + | NonUndefinedGuard } > @@ -42,7 +47,9 @@ export type DefinedInitialDataOptions< TQueryKey extends QueryKey = QueryKey, > = Accessor< QueryOptions & { - initialData: TQueryFnData | (() => TQueryFnData) + initialData: + | NonUndefinedGuard + | (() => NonUndefinedGuard) } > diff --git a/packages/solid-query/src/useQuery.ts b/packages/solid-query/src/useQuery.ts index d7a36aba40f..1c96650af0f 100644 --- a/packages/solid-query/src/useQuery.ts +++ b/packages/solid-query/src/useQuery.ts @@ -14,6 +14,56 @@ import type { UndefinedInitialDataOptions, } from './queryOptions' +/** + * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. + * The query runs when the options call for it — `enabled: false` skips the initial fetch. + * + * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless + * a `select` changes `TData` to include `undefined`). + * @param options - An accessor returning the {@link DefinedInitialDataOptions} to use — everything you can + * pass to `useQuery`, with `initialData` set. + * @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context + * will be used. + * @returns The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a + * fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's + * type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for + * convenience. + * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`. + * @example + * ```tsx + * import { For } from 'solid-js' + * import { useQuery } from '@tanstack/solid-query' + * + * function Posts() { + * // `postsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the + * // list stays visible alongside the error. + * const postsQuery = useQuery(() => ({ + * queryKey: ['posts'], + * queryFn: fetchPosts, + * initialData: [], + * })) + * + * return ( + *
+ * {postsQuery.isError ? Error: {postsQuery.error.message} : null} + *
    + * {(post) =>
  • {post.title}
  • }
    + *
+ *
+ * ) + * } + * ``` + */ +export function useQuery< + TQueryFnData = unknown, + TError = DefaultError, + TData = TQueryFnData, + TQueryKey extends QueryKey = QueryKey, +>( + options: DefinedInitialDataOptions, + queryClient?: () => QueryClient, +): DefinedUseQueryResult + /** * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. * The query runs when the options call for it — `enabled: false` skips the initial fetch. @@ -184,56 +234,6 @@ export function useQuery< options: UndefinedInitialDataOptions, queryClient?: () => QueryClient, ): UseQueryResult - -/** - * Subscribes to a query: a declarative dependency on an asynchronous source of data that is tied to a unique key. - * The query runs when the options call for it — `enabled: false` skips the initial fetch. - * - * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless - * a `select` changes `TData` to include `undefined`). - * @param options - An accessor returning the {@link DefinedInitialDataOptions} to use — everything you can - * pass to `useQuery`, with `initialData` set. - * @param queryClient - An accessor for a custom `QueryClient`. Otherwise, the one from the nearest context - * will be used. - * @returns The current query result, as a Solid store, typed so that `status` is `success` — or `error` if a - * fetch attempt fails while keeping the existing data (`status` never resolves to `pending` in this overload's - * type, since `initialData` guarantees data upfront). `isSuccess`/`isError` are derived booleans for - * convenience. - * @see {@link queryOptions} to share these options between `useQuery` and imperative APIs like `queryClient.query`. - * @example - * ```tsx - * import { For } from 'solid-js' - * import { useQuery } from '@tanstack/solid-query' - * - * function Posts() { - * // `postsQuery.data` is never `undefined`, thanks to `initialData` — even if a refetch fails, so the - * // list stays visible alongside the error. - * const postsQuery = useQuery(() => ({ - * queryKey: ['posts'], - * queryFn: fetchPosts, - * initialData: [], - * })) - * - * return ( - *
- * {postsQuery.isError ? Error: {postsQuery.error.message} : null} - *
    - * {(post) =>
  • {post.title}
  • }
    - *
- *
- * ) - * } - * ``` - */ -export function useQuery< - TQueryFnData = unknown, - TError = DefaultError, - TData = TQueryFnData, - TQueryKey extends QueryKey = QueryKey, ->( - options: DefinedInitialDataOptions, - queryClient?: () => QueryClient, -): DefinedUseQueryResult export function useQuery< TQueryFnData, TError = DefaultError,