{"version":3,"file":"usePrefetchInfiniteQuery.cjs","names":["useQueryClient","noop"],"sources":["../../src/usePrefetchInfiniteQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type {\n  DefaultError,\n  InfiniteData,\n  QueryClient,\n  QueryKey,\n} from '@tanstack/query-core'\nimport type { UsePrefetchInfiniteQueryOptions } from './types'\n\n/**\n * `usePrefetchInfiniteQuery` does not return anything, it should be used just to fire a prefetch during render,\n * before a suspense boundary that wraps a component that uses `useSuspenseInfiniteQuery`. You can pass\n * everything to `usePrefetchInfiniteQuery` that you can pass to `queryClient.infiniteQuery`, though\n * `queryKey`, `initialPageParam`, and `getNextPageParam` are always required, and `queryFn` is required unless\n * a default query function has been defined.\n *\n * `getNextPageParam` receives both the last page of the infinite list of data and the full array of all pages,\n * as well as pageParam information, and should return a single variable that will be passed to your query\n * function as `context.pageParam`. Return `undefined` or `null` to indicate there is no next page available.\n *\n * The prefetch is skipped if the query already has any cached state — including a `pending`/`error` state left\n * over from a previous attempt — so calling this on every render is cheap and won't refetch data that's\n * already there or already in flight.\n * @param options - The {@link UsePrefetchInfiniteQueryOptions} to use — everything you can pass to `queryClient.infiniteQuery`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @example\n * ```tsx\n * import { Suspense } from 'react'\n * import { infiniteQueryOptions, usePrefetchInfiniteQuery } from '@tanstack/react-query'\n *\n * const projectsOptions = infiniteQueryOptions({\n *   queryKey: ['projects'],\n *   queryFn: ({ pageParam }) => fetchProjects(pageParam),\n *   initialPageParam: 0,\n *   getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * function App() {\n *   // Fire the prefetch during render, before the suspense boundary below.\n *   usePrefetchInfiniteQuery(projectsOptions)\n *\n *   return (\n *     <Suspense fallback={<h1>Loading projects...</h1>}>\n *       <Projects />\n *     </Suspense>\n *   )\n * }\n * ```\n */\nexport function usePrefetchInfiniteQuery<\n  TQueryFnData = unknown,\n  TError = DefaultError,\n  TData = InfiniteData<TQueryFnData>,\n  TQueryKey extends QueryKey = QueryKey,\n  TPageParam = unknown,\n>(\n  options: UsePrefetchInfiniteQueryOptions<\n    TQueryFnData,\n    TError,\n    TData,\n    TQueryKey,\n    TPageParam\n  >,\n  queryClient?: QueryClient,\n): void {\n  const client = useQueryClient(queryClient)\n\n  if (!client.getQueryState(options.queryKey)) {\n    void client.infiniteQuery(options).catch(noop)\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,yBAOd,SAOA,aACM;CACN,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,cAAc,OAAO,CAAC,CAAC,MAAMC,qBAAAA,IAAI;AAEjD"}