mirror of
https://github.com/nicotsx/zerobyte.git
synced 2026-04-17 21:37:06 -04:00
18 lines
500 B
TypeScript
18 lines
500 B
TypeScript
import type { FetchQueryOptions, QueryClient, QueryKey } from "@tanstack/react-query";
|
|
|
|
export async function prefetchOrSkip<
|
|
TQueryFnData = unknown,
|
|
TError = Error,
|
|
TData = TQueryFnData,
|
|
TQueryKey extends QueryKey = QueryKey,
|
|
>(
|
|
queryClient: QueryClient,
|
|
options: FetchQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
timeoutMs = 150,
|
|
): Promise<void> {
|
|
await Promise.race([
|
|
queryClient.prefetchQuery(options),
|
|
new Promise<void>((resolve) => setTimeout(resolve, timeoutMs)),
|
|
]);
|
|
}
|