{"version":3,"file":"usePrefetchQuery.js","names":[],"sources":["../../src/usePrefetchQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\nimport type { UsePrefetchQueryOptions } from './types'\n\n/**\n * `usePrefetchQuery` does not return anything, it should be used just to fire a prefetch during render, before\n * a suspense boundary that wraps a component that uses `useSuspenseQuery`. You can pass everything to\n * `usePrefetchQuery` that you can pass to `queryClient.query`, though `queryKey` is always required, and\n * `queryFn` is required unless a default query function has been defined.\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 *\n * @param options - The {@link UsePrefetchQueryOptions} to use — everything you can pass to `queryClient.query`.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns `void` — nothing is returned.\n *\n * @example\n * ```tsx\n * import { Suspense } from 'react'\n * import { usePrefetchQuery } from '@tanstack/react-query'\n *\n * function App() {\n *   // Fire the prefetch during render, before the suspense boundary below.\n *   usePrefetchQuery({\n *     queryKey: ['posts'],\n *     queryFn: fetchPosts,\n *   })\n *\n *   return (\n *     <Suspense fallback={<h1>Loading posts...</h1>}>\n *       <Posts />\n *     </Suspense>\n *   )\n * }\n * ```\n */\nexport function usePrefetchQuery<\n  TQueryFnData = unknown,\n  TError = DefaultError,\n  TData = TQueryFnData,\n  TQueryData = TQueryFnData,\n  TQueryKey extends QueryKey = QueryKey,\n>(\n  options: UsePrefetchQueryOptions<\n    TQueryFnData,\n    TError,\n    TData,\n    TQueryData,\n    TQueryKey\n  >,\n  queryClient?: QueryClient,\n): void {\n  const client = useQueryClient(queryClient)\n\n  if (!client.getQueryState(options.queryKey)) {\n    void client.query(options).catch(noop)\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,SAAgB,iBAOd,SAOA,aACM;CACN,MAAM,SAAS,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,MAAM,OAAO,CAAC,CAAC,MAAM,IAAI;AAEzC"}