Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(react-query): fix queryOptions with initialData to work on useSuspenseQueries #8658

Merged
merged 2 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/react-query/src/__tests__/useSuspenseQueries.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,17 @@ describe('UseSuspenseQueries config object overload', () => {
expectTypeOf(data).toEqualTypeOf<Data>()
})
})

it('queryOptions with initialData works on useSuspenseQueries', () => {
const query1 = queryOptions({
queryKey: ['key1'],
queryFn: () => 'Query Data',
initialData: 'initial data',
})

const queryResults = useSuspenseQueries({ queries: [query1] })
const query1Data = queryResults[0].data

expectTypeOf(query1Data).toEqualTypeOf<string>()
})
})
9 changes: 8 additions & 1 deletion packages/react-query/src/queryOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,14 @@ export function queryOptions<
TQueryKey extends QueryKey = QueryKey,
>(
options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
): Omit<
DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,
'queryFn'
> & {
queryFn?: Exclude<
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],
SkipToken | undefined
>
queryKey: DataTag<TQueryKey, TQueryFnData, TError>
}

Expand Down
Loading