@tanstack/react-query
Advanced tools
Comparing version 5.54.1 to 5.55.0
@@ -1,6 +0,6 @@ | ||
import { DefaultError, QueryKey, FetchQueryOptions, FetchInfiniteQueryOptions } from '@tanstack/query-core'; | ||
import { DefaultError, QueryKey, FetchQueryOptions, QueryClient, FetchInfiniteQueryOptions } from '@tanstack/query-core'; | ||
declare function usePrefetchQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>): void; | ||
declare function usePrefetchInfiniteQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): void; | ||
declare function usePrefetchQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): void; | ||
declare function usePrefetchInfiniteQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: QueryClient): void; | ||
export { usePrefetchInfiniteQuery, usePrefetchQuery }; |
// src/prefetch.ts | ||
import { useQueryClient } from "./QueryClientProvider.js"; | ||
function usePrefetchQuery(options) { | ||
const queryClient = useQueryClient(); | ||
if (!queryClient.getQueryState(options.queryKey)) { | ||
queryClient.prefetchQuery(options); | ||
function usePrefetchQuery(options, queryClient) { | ||
const client = useQueryClient(queryClient); | ||
if (!client.getQueryState(options.queryKey)) { | ||
client.prefetchQuery(options); | ||
} | ||
} | ||
function usePrefetchInfiniteQuery(options) { | ||
const queryClient = useQueryClient(); | ||
if (!queryClient.getQueryState(options.queryKey)) { | ||
queryClient.prefetchInfiniteQuery(options); | ||
function usePrefetchInfiniteQuery(options, queryClient) { | ||
const client = useQueryClient(queryClient); | ||
if (!client.getQueryState(options.queryKey)) { | ||
client.prefetchInfiniteQuery(options); | ||
} | ||
@@ -14,0 +14,0 @@ } |
@@ -1,6 +0,6 @@ | ||
import { DefaultError, QueryKey, FetchQueryOptions, FetchInfiniteQueryOptions } from '@tanstack/query-core'; | ||
import { DefaultError, QueryKey, FetchQueryOptions, QueryClient, FetchInfiniteQueryOptions } from '@tanstack/query-core'; | ||
declare function usePrefetchQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>): void; | ||
declare function usePrefetchInfiniteQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): void; | ||
declare function usePrefetchQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>, queryClient?: QueryClient): void; | ||
declare function usePrefetchInfiniteQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: FetchInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient?: QueryClient): void; | ||
export { usePrefetchInfiniteQuery, usePrefetchQuery }; |
// src/prefetch.ts | ||
import { useQueryClient } from "./QueryClientProvider.js"; | ||
function usePrefetchQuery(options) { | ||
const queryClient = useQueryClient(); | ||
if (!queryClient.getQueryState(options.queryKey)) { | ||
queryClient.prefetchQuery(options); | ||
function usePrefetchQuery(options, queryClient) { | ||
const client = useQueryClient(queryClient); | ||
if (!client.getQueryState(options.queryKey)) { | ||
client.prefetchQuery(options); | ||
} | ||
} | ||
function usePrefetchInfiniteQuery(options) { | ||
const queryClient = useQueryClient(); | ||
if (!queryClient.getQueryState(options.queryKey)) { | ||
queryClient.prefetchInfiniteQuery(options); | ||
function usePrefetchInfiniteQuery(options, queryClient) { | ||
const client = useQueryClient(queryClient); | ||
if (!client.getQueryState(options.queryKey)) { | ||
client.prefetchInfiniteQuery(options); | ||
} | ||
@@ -14,0 +14,0 @@ } |
{ | ||
"name": "@tanstack/react-query", | ||
"version": "5.54.1", | ||
"version": "5.55.0", | ||
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React", | ||
@@ -5,0 +5,0 @@ "author": "tannerlinsley", |
@@ -6,2 +6,3 @@ import { useQueryClient } from './QueryClientProvider' | ||
FetchQueryOptions, | ||
QueryClient, | ||
QueryKey, | ||
@@ -15,7 +16,10 @@ } from '@tanstack/query-core' | ||
TQueryKey extends QueryKey = QueryKey, | ||
>(options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>) { | ||
const queryClient = useQueryClient() | ||
>( | ||
options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>, | ||
queryClient?: QueryClient, | ||
) { | ||
const client = useQueryClient(queryClient) | ||
if (!queryClient.getQueryState(options.queryKey)) { | ||
queryClient.prefetchQuery(options) | ||
if (!client.getQueryState(options.queryKey)) { | ||
client.prefetchQuery(options) | ||
} | ||
@@ -38,8 +42,9 @@ } | ||
>, | ||
queryClient?: QueryClient, | ||
) { | ||
const queryClient = useQueryClient() | ||
const client = useQueryClient(queryClient) | ||
if (!queryClient.getQueryState(options.queryKey)) { | ||
queryClient.prefetchInfiniteQuery(options) | ||
if (!client.getQueryState(options.queryKey)) { | ||
client.prefetchInfiniteQuery(options) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1107107
22068