62 lines
2.2 KiB
JavaScript
62 lines
2.2 KiB
JavaScript
"use client";
|
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
const require_rolldown_runtime = require("./rolldown-runtime-VH7oDXx4.cjs");
|
|
let react = require("react");
|
|
react = require_rolldown_runtime.__toESM(react, 1);
|
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
//#region src/QueryClientProvider.tsx
|
|
/**
|
|
* The context that `useQueryClient` reads from. `QueryClientProvider` is the normal way to set it.
|
|
*/
|
|
const QueryClientContext = react.createContext(void 0);
|
|
/**
|
|
* The `useQueryClient` hook returns the current `QueryClient` instance.
|
|
*
|
|
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
* be used.
|
|
* @returns The current `QueryClient` instance.
|
|
* @throws If no `queryClient` argument is passed and no `QueryClientProvider` is found in the component tree.
|
|
*/
|
|
const useQueryClient = (queryClient) => {
|
|
const client = react.useContext(QueryClientContext);
|
|
if (queryClient) return queryClient;
|
|
if (!client) throw new Error("No QueryClient set, use QueryClientProvider to set one");
|
|
return client;
|
|
};
|
|
/**
|
|
* Use the `QueryClientProvider` component to connect and provide a `QueryClient` to your application. Also
|
|
* calls `client.mount()`/`client.unmount()` as this component mounts/unmounts, which subscribes the client to
|
|
* focus/online events (resuming any paused mutations and refetching as needed when the app regains focus or
|
|
* comes back online).
|
|
*
|
|
* @returns The provided `children`, wrapped so they can read the `QueryClient` via `useQueryClient`.
|
|
*
|
|
* @example
|
|
* ```tsx
|
|
* import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
*
|
|
* const queryClient = new QueryClient()
|
|
*
|
|
* function App() {
|
|
* return <QueryClientProvider client={queryClient}>...</QueryClientProvider>
|
|
* }
|
|
* ```
|
|
*/
|
|
const QueryClientProvider = ({ client, children }) => {
|
|
react.useEffect(() => {
|
|
client.mount();
|
|
return () => {
|
|
client.unmount();
|
|
};
|
|
}, [client]);
|
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(QueryClientContext.Provider, {
|
|
value: client,
|
|
children
|
|
});
|
|
};
|
|
//#endregion
|
|
exports.QueryClientContext = QueryClientContext;
|
|
exports.QueryClientProvider = QueryClientProvider;
|
|
exports.useQueryClient = useQueryClient;
|
|
|
|
//# sourceMappingURL=QueryClientProvider.cjs.map
|