{"version":3,"file":"QueryClientProvider.cjs","names":["React"],"sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\n\n/**\n * The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.\n */\nexport const QueryClientContext = React.createContext<QueryClient | undefined>(\n  undefined,\n)\n\n/**\n * The `useQueryClient` hook returns the current `QueryClient` instance.\n * @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will\n * be used.\n * @returns The current `QueryClient` instance.\n * @throws {Error} If no `queryClient` argument is passed and no `QueryClientProvider` is found in the\n * component tree.\n */\nexport const useQueryClient = (queryClient?: QueryClient) => {\n  const client = React.useContext(QueryClientContext)\n\n  if (queryClient) {\n    return queryClient\n  }\n\n  if (!client) {\n    throw new Error('No QueryClient set, use QueryClientProvider to set one')\n  }\n\n  return client\n}\n\n/**\n * The props accepted by `QueryClientProvider`.\n */\nexport type QueryClientProviderProps = {\n  /**\n   * **Required**\n   *\n   * The `QueryClient` instance to provide.\n   */\n  client: QueryClient\n  /**\n   * The components that get access to the provided `QueryClient`.\n   */\n  children?: React.ReactNode\n}\n\n/**\n * Use the `QueryClientProvider` component to connect and provide a `QueryClient` to your application. Also\n * calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to\n * focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or\n * comes back online).\n * @param props - The `client` to provide, and the `children` that get access to it.\n * @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.\n * @example\n * ```tsx\n * import { QueryClient, QueryClientProvider } from '@tanstack/react-query'\n *\n * const queryClient = new QueryClient()\n *\n * function App() {\n *   return <QueryClientProvider client={queryClient}>...</QueryClientProvider>\n * }\n * ```\n */\nexport const QueryClientProvider = ({\n  client,\n  children,\n}: QueryClientProviderProps): React.JSX.Element => {\n  React.useEffect(() => {\n    client.mount()\n    return () => {\n      client.unmount()\n    }\n  }, [client])\n\n  return (\n    <QueryClientContext.Provider value={client}>\n      {children}\n    </QueryClientContext.Provider>\n  )\n}\n"],"mappings":";;;;;;;;;;AAQA,MAAa,qBAAqBA,MAAM,cACtC,KAAA,CACF;;;;;;;;;AAUA,MAAa,kBAAkB,gBAA8B;CAC3D,MAAM,SAASA,MAAM,WAAW,kBAAkB;CAElD,IAAI,aACF,OAAO;CAGT,IAAI,CAAC,QACH,MAAM,IAAI,MAAM,wDAAwD;CAG1E,OAAO;AACT;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,uBAAuB,EAClC,QACA,eACiD;CACjD,MAAM,gBAAgB;EACpB,OAAO,MAAM;EACb,aAAa;GACX,OAAO,QAAQ;EACjB;CACF,GAAG,CAAC,MAAM,CAAC;CAEX,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,mBAAmB,UAApB;EAA6B,OAAO;EACjC;CAC0B,CAAA;AAEjC"}