@techsio/storefront-data
Version:
Medusa-first storefront data layer built on TanStack Query.
32 lines • 1.18 kB
TypeScript
/**
* Get a per-request QueryClient for Server Components.
*
* Uses React's cache() to ensure the same QueryClient instance
* is returned throughout a single server request. This allows
* multiple server components to share prefetched data.
*
* @remarks
* React's `cache()` memoization applies only when called during a React Server
* Component render. Calling `getServerQueryClient()` outside an RSC context
* (for example in route handlers or standalone server utilities) bypasses this
* request-scoped memoization and creates a new QueryClient instance per call.
*
* @example
* ```tsx
* // app/products/layout.tsx (Server Component)
* import { getServerQueryClient } from "@techsio/storefront-data/server/get-query-client"
*
* export default async function Layout({ children }) {
* const queryClient = getServerQueryClient()
* await queryClient.prefetchQuery(...)
*
* return (
* <HydrationBoundary state={dehydrate(queryClient)}>
* {children}
* </HydrationBoundary>
* )
* }
* ```
*/
export declare const getServerQueryClient: () => import("@tanstack/react-query").QueryClient;
//# sourceMappingURL=get-query-client.d.ts.map