-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(react-query): add usePrefetchQuery, usePrefetchInfiniteQuery
Co-authored-by: halfstack <61955474+ha1fstack@users.noreply.github.com> Co-authored-by: GwanSik Kim <39869096+gwansikk@users.noreply.github.com>
- Loading branch information
1 parent
779121f
commit 2f3e640
Showing
6 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { type FetchInfiniteQueryOptions, type QueryKey, useQueryClient } from '@tanstack/react-query' | ||
|
||
export function usePrefetchInfiniteQuery< | ||
TQueryFnData = unknown, | ||
TError = unknown, | ||
TData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
>(options: FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>) { | ||
const queryClient = useQueryClient() | ||
|
||
if (typeof options.queryKey !== 'undefined' && !queryClient.getQueryState(options.queryKey)) { | ||
queryClient.prefetchInfiniteQuery(options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { type FetchQueryOptions, type QueryKey, useQueryClient } from '@tanstack/react-query' | ||
|
||
export function usePrefetchQuery< | ||
TQueryFnData = unknown, | ||
TError = unknown, | ||
TData = TQueryFnData, | ||
TQueryKey extends QueryKey = QueryKey, | ||
>(options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>) { | ||
const queryClient = useQueryClient() | ||
|
||
if (typeof options.queryKey !== 'undefined' && !queryClient.getQueryState(options.queryKey)) { | ||
queryClient.prefetchQuery(options) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { usePrefetchInfiniteQuery as original_usePrefetchInfiniteQuery } from '@tanstack/react-query' | ||
|
||
/** | ||
* This feature is officially supported in \@tanstack/react-query@5, You can proceed with the migration. | ||
* @deprecated Use `usePrefetchInfiniteQuery` from \@tanstack/react-query@5 | ||
* @example | ||
* ```diff | ||
* - import { usePrefetchInfiniteQuery } from '@suspensive/react-query' | ||
* + import { usePrefetchInfiniteQuery } from '@tanstack/react-query' | ||
* ``` | ||
*/ | ||
export const usePrefetchInfiniteQuery = original_usePrefetchInfiniteQuery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { usePrefetchQuery as original_usePrefetchQuery } from '@tanstack/react-query' | ||
|
||
/** | ||
* This feature is officially supported in \@tanstack/react-query@5, You can proceed with the migration. | ||
* @deprecated Use `usePrefetchQuery` from \@tanstack/react-query@5 | ||
* @example | ||
* ```diff | ||
* - import { usePrefetchQuery } from '@suspensive/react-query' | ||
* + import { usePrefetchQuery } from '@tanstack/react-query' | ||
* ``` | ||
*/ | ||
export const usePrefetchQuery = original_usePrefetchQuery |