UNPKG

amplifyquery

Version:
104 lines (103 loc) 3.5 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.AmplifyQueryProvider = AmplifyQueryProvider; exports.createCustomQueryProvider = createCustomQueryProvider; const React = __importStar(require("react")); const react_query_1 = require("@tanstack/react-query"); const query_1 = require("./query"); /** * TanStack Query Provider for AmplifyQuery * * This component provides the QueryClient to the entire application. * Use this at the root of your application to enable React Query. * * @example * ```tsx * import { AmplifyQueryProvider } from 'amplifyquery/provider'; * * function App() { * return ( * <AmplifyQueryProvider> * <YourApp /> * </AmplifyQueryProvider> * ); * } * ``` */ function AmplifyQueryProvider({ children, }) { // Get the shared query client instance const queryClient = (0, query_1.getQueryClient)(); return (<react_query_1.QueryClientProvider client={queryClient}>{children}</react_query_1.QueryClientProvider>); } /** * Creates a custom QueryClient provider with configuration options * * @param customQueryClient Optional custom QueryClient instance * @returns A provider component with the custom client * * @example * ```tsx * import { createCustomQueryProvider } from 'amplifyquery/provider'; * import { QueryClient } from '@tanstack/react-query'; * * // Create a custom client with specific options * const customClient = new QueryClient({ * defaultOptions: { * queries: { * staleTime: 1000 * 60 * 5, * }, * }, * }); * * // Create a provider with this client * const CustomProvider = createCustomQueryProvider(customClient); * * function App() { * return ( * <CustomProvider> * <YourApp /> * </CustomProvider> * ); * } * ``` */ function createCustomQueryProvider(customQueryClient) { return ({ children }) => { // Use custom client or get the default one const client = customQueryClient || (0, query_1.getQueryClient)(); return (<react_query_1.QueryClientProvider client={client}>{children}</react_query_1.QueryClientProvider>); }; }