- createTRPCContext + useTRPC hook for typed client access - NextTrpcProvider with SSR-safe absolute URL resolution - TanstackTrpcProvider for TanStack Start apps - /api/trpc catch-all route handler in web-next - Wire NextTrpcProvider into app providers - Add @repo/core-trpc to transpilePackages
23 lines
551 B
TypeScript
23 lines
551 B
TypeScript
import { QueryClient } from "@tanstack/react-query";
|
|
|
|
let clientQueryClient: QueryClient | undefined;
|
|
|
|
const defaultOptions = {
|
|
queries: {
|
|
staleTime: 30 * 1000,
|
|
refetchOnWindowFocus: false,
|
|
},
|
|
};
|
|
|
|
export function getQueryClient(): QueryClient {
|
|
if (typeof window === "undefined") {
|
|
// Server: always create a new instance per request
|
|
return new QueryClient({ defaultOptions });
|
|
}
|
|
// Browser: singleton
|
|
if (!clientQueryClient) {
|
|
clientQueryClient = new QueryClient({ defaultOptions });
|
|
}
|
|
return clientQueryClient;
|
|
}
|