-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(v4): backport some v5 apis to v4 branch #8754
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
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Hey @TkDodo / maintainers, hope you are doing good. Would appreciate some feedback on this, and whether this would be likely accepted or not. Cheers. |
Co-authored-by: Dominik Dorfmeister <[email protected]>
export interface UseSuspenseQueryOptions< | ||
TQueryFnData = unknown, | ||
TError = unknown, | ||
TData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
> extends Omit< | ||
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, | ||
'enabled' | 'suspense' | 'placeholderData' | 'keepPreviousData' | ||
> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export interface UseSuspenseQueryOptions< | |
TQueryFnData = unknown, | |
TError = unknown, | |
TData = TQueryFnData, | |
TQueryKey extends QueryKey = QueryKey, | |
> extends Omit< | |
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, | |
'enabled' | 'suspense' | 'placeholderData' | 'keepPreviousData' | |
> {} | |
export interface UseSuspenseQueryOptions< | |
TQueryFnData = unknown, | |
TError = unknown, | |
TData = TQueryFnData, | |
TQueryKey extends QueryKey = QueryKey, | |
> extends Omit< | |
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, | |
'enabled' | 'suspense' | 'placeholderData' | 'keepPreviousData' | 'useErrorBoundary' | |
> {} |
return useBaseQuery( | ||
{ | ||
...options, | ||
enabled: true, | ||
suspense: true, | ||
placeholderData: undefined, | ||
}, | ||
QueryObserver, | ||
) as UseSuspenseQueryResult<TData, TError> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid allowing useErrorBoundary to be set to false here.
return useBaseQuery( | |
{ | |
...options, | |
enabled: true, | |
suspense: true, | |
placeholderData: undefined, | |
}, | |
QueryObserver, | |
) as UseSuspenseQueryResult<TData, TError> | |
return useBaseQuery( | |
{ | |
...options, | |
enabled: true, | |
suspense: true, | |
placeholderData: undefined, | |
useErrorBoundary: true, | |
}, | |
QueryObserver, | |
) as UseSuspenseQueryResult<TData, TError> |
export function queryOptions< | ||
TQueryFnData = unknown, | ||
TError = unknown, | ||
TData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
>( | ||
options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, | ||
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & { | ||
queryKey: TQueryKey | ||
} | ||
|
||
export function queryOptions(options: unknown) { | ||
return options | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, we should add type tests for queryOptions using Vitest.
It’s important to guarantee type safety:
- queryOptions with useQuery
- queryOptions with useQueries
- queryOptions with useSuspenseQuery
- queryOptions with useSuspenseQueries
- queryOptions with queryClient methods
You can refer to the link below for a good example of what and how to type test:
https://github.com/toss/suspensive/tree/main/packages/react-query-4/src
I really appreciate this work — I've created @suspensive/react-query in the past because I use TanStack Query v4 at my company yet.
Your approach will actually help me remove some unnecessary code from my project.
Let’s tackle this step by step and make it perfect.
Hey @manudeli, I added you as a collaborator to the fork, I don't plan on working on this in the near future, so please feel free to push changes directly to the branch with your suggestions. Cheers. |
Hi @danielpza, thanks for putting together the initial work — the change around isPending is a useful direction. |
This is an attempt to backport some of the new api in tanstack query v5 to v4 branch, which should make it easier to developers still on v4 to migrate to v5 by making small incremental changes to the codebase without having to commit to a big change.
Apis to backport:
Additionally this pull request adds a jsdoc
@deprecated
label to some of the apis that are removed/renamed in v5 and suggests some alternativesCompared to v5, no new functionality is added, so when merging back to main discard the changes introduced in this pull request