UNPKG

create-better-t-stack

Version:

A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations

40 lines (36 loc) 987 B
import type { AppRouter } from "../../../server/src/routers"; import { QueryCache, QueryClient } from "@tanstack/react-query"; import { createTRPCClient, httpBatchLink } from "@trpc/client"; import { createTRPCOptionsProxy } from "@trpc/tanstack-react-query"; import { toast } from "sonner"; export const queryClient = new QueryClient({ queryCache: new QueryCache({ onError: (error) => { toast.error(error.message, { action: { label: "retry", onClick: () => { queryClient.invalidateQueries(); }, }, }); }, }), }); export const trpcClient = createTRPCClient<AppRouter>({ links: [ httpBatchLink({ url: `${import.meta.env.VITE_SERVER_URL}/trpc`, fetch(url, options) { return fetch(url, { ...options, credentials: "include", }); }, }), ], }); export const trpc = createTRPCOptionsProxy<AppRouter>({ client: trpcClient, queryClient, });