-
Notifications
You must be signed in to change notification settings - Fork 74
fix(react-query): update peerDependency, @tanstack/react-query to version 4.40.0 and deprecate old options #1639
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
Changes from 4 commits
0135458
223d384
07423be
2fb1379
9d2e076
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@suspensive/react-query-4": minor | ||
"@suspensive/react-query-5": minor | ||
"@suspensive/react-query": minor | ||
--- | ||
|
||
chore: update react-query dependencies to version 4.40.0 and deprecate old options | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import { type UseQueryResult, useQueries, useQuery, useQueryClient } from '@tanstack/react-query' | ||
import { | ||
type UseQueryResult, | ||
type UseSuspenseQueryResult, | ||
queryOptions, | ||
useQueries, | ||
useQuery, | ||
useQueryClient, | ||
useSuspenseQueries, | ||
useSuspenseQuery, | ||
} from '@tanstack/react-query' | ||
import { describe, expectTypeOf, it } from 'vitest' | ||
import { queryOptions } from './queryOptions' | ||
import { SuspenseQuery } from './SuspenseQuery' | ||
import { queryKey } from './test-utils' | ||
import { usePrefetchQuery } from './usePrefetchQuery' | ||
import { useSuspenseQueries } from './useSuspenseQueries' | ||
import { type UseSuspenseQueryResult, useSuspenseQuery } from './useSuspenseQuery' | ||
|
||
const query = { | ||
options1: () => | ||
|
@@ -58,26 +64,30 @@ describe('queryOptions', () => { | |
))() | ||
}) | ||
it('should be used with useQueries', () => { | ||
const [query1, query2, query3] = useQueries({ | ||
const [ | ||
query1, | ||
query2, | ||
// query3 | ||
] = useQueries({ | ||
queries: [ | ||
query.options1(), | ||
{ ...query.options2() }, | ||
queryOptions({ | ||
queryKey: [...queryKey, 4] as const, | ||
queryFn: () => Promise.resolve({ field: 'success' }), | ||
select: (data) => { | ||
expectTypeOf(data).toEqualTypeOf<{ field: string }>() | ||
return data.field | ||
}, | ||
}), | ||
// queryOptions({ | ||
// queryKey: [...queryKey, 4] as const, | ||
// queryFn: () => Promise.resolve({ field: 'success' }), | ||
// select: (data) => { | ||
// expectTypeOf(data).toEqualTypeOf<{ field: string }>() | ||
// return data.field | ||
// }, | ||
// }), | ||
], | ||
}) | ||
expectTypeOf(query1).toEqualTypeOf<UseQueryResult<{ field: string }>>() | ||
expectTypeOf(query1.data).toEqualTypeOf<{ field: string } | undefined>() | ||
expectTypeOf(query2).toEqualTypeOf<UseQueryResult<{ field: string }>>() | ||
expectTypeOf(query2.data).toEqualTypeOf<{ field: string } | undefined>() | ||
expectTypeOf(query3).toEqualTypeOf<UseQueryResult<string>>() | ||
expectTypeOf(query3.data).toEqualTypeOf<string | undefined>() | ||
// expectTypeOf(query3).toEqualTypeOf<UseQueryResult<string>>() | ||
// expectTypeOf(query3.data).toEqualTypeOf<string | undefined>() | ||
}) | ||
Comment on lines
+67
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason for commenting out instead of removing it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
it('should be used with useSuspenseQueries', () => { | ||
const [query1, query2, query3] = useSuspenseQueries({ | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,6 +1,9 @@ | ||||||||||||
import type { QueryKey, UseQueryOptions } from '@tanstack/react-query' | ||||||||||||
import { type QueryKey, type UseQueryOptions, queryOptions as original_queryOptions } from '@tanstack/react-query' | ||||||||||||
import type { OmitKeyof, RequiredKeyof } from './utility-types' | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* @deprecated There is no `SelectedQueryOptions` in \@tanstack/react-query@^4.40.0. | ||||||||||||
*/ | ||||||||||||
export type SelectedQueryOptions< | ||||||||||||
TQueryFnData = unknown, | ||||||||||||
TError = unknown, | ||||||||||||
|
@@ -29,6 +32,9 @@ export type SelectedQueryOptions< | |||||||||||
select: (data: TQueryFnData) => TData | ||||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* @deprecated There is no `UnSelectedQueryOptions` in \@tanstack/react-query@^4.40.0. | ||||||||||||
*/ | ||||||||||||
export type UnSelectedQueryOptions< | ||||||||||||
TQueryFnData = unknown, | ||||||||||||
TError = unknown, | ||||||||||||
|
@@ -58,29 +64,12 @@ export type UnSelectedQueryOptions< | |||||||||||
} | ||||||||||||
|
||||||||||||
/** | ||||||||||||
* Creates a reusable query options object that can be used across different query hooks. | ||||||||||||
* Provides better type inference and easier query key management. | ||||||||||||
* | ||||||||||||
* @see {@link https://suspensive.org/docs/react-query/queryOptions Suspensive Docs} | ||||||||||||
* This feature is officially supported in \@tanstack/react-query@^4.40.0, You can proceed with the migration. | ||||||||||||
* @deprecated Use `queryOptions` from \@tanstack/react-query@^4.40.0 | ||||||||||||
* @example | ||||||||||||
* ```diff | ||||||||||||
Comment on lines
+68
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
this is a suggestion |
||||||||||||
* - import { queryOptions } from '@suspensive/react-query' | ||||||||||||
* + import { queryOptions } from '@tanstack/react-query' | ||||||||||||
* ``` | ||||||||||||
*/ | ||||||||||||
export function queryOptions< | ||||||||||||
TQueryFnData = unknown, | ||||||||||||
TError = unknown, | ||||||||||||
TData = TQueryFnData, | ||||||||||||
TQueryKey extends QueryKey = QueryKey, | ||||||||||||
>( | ||||||||||||
options: SelectedQueryOptions<TQueryFnData, TError, TData, TQueryKey> | ||||||||||||
): SelectedQueryOptions<TQueryFnData, TError, TData, TQueryKey> | ||||||||||||
|
||||||||||||
export function queryOptions< | ||||||||||||
TQueryFnData = unknown, | ||||||||||||
TError = unknown, | ||||||||||||
TData = TQueryFnData, | ||||||||||||
TQueryKey extends QueryKey = QueryKey, | ||||||||||||
>( | ||||||||||||
options: UnSelectedQueryOptions<TQueryFnData, TError, TData, TQueryKey> | ||||||||||||
): UnSelectedQueryOptions<TQueryFnData, TError, TData, TQueryKey> | ||||||||||||
|
||||||||||||
export function queryOptions(options: unknown) { | ||||||||||||
return options | ||||||||||||
} | ||||||||||||
export const queryOptions = original_queryOptions |
Uh oh!
There was an error while loading. Please reload this page.