fix orpc templates (#302)

This commit is contained in:
Aman Varshney
2025-06-05 21:46:13 +05:30
parent a8ef5e8928
commit 2e6454ab33
15 changed files with 124 additions and 163 deletions

View File

@@ -1,17 +1,13 @@
import { createORPCClient } from "@orpc/client";
import { RPCLink } from "@orpc/client/fetch";
import { createTanstackQueryUtils } from "@orpc/tanstack-query";
import type { RouterUtils } from "@orpc/tanstack-query";
import type { RouterClient } from "@orpc/server";
import { QueryCache, QueryClient } from "@tanstack/react-query";
import { createContext, useContext } from "react";
import type { appRouter } from "../../server/src/routers";
{{#if auth}}
import { authClient } from "@/lib/auth-client";
{{/if}}
type ORPCReactUtils = RouterUtils<RouterClient<typeof appRouter>>;
export const queryClient = new QueryClient({
queryCache: new QueryCache({
onError: (error) => {
@@ -37,13 +33,3 @@ export const link = new RPCLink({
export const client: RouterClient<typeof appRouter> = createORPCClient(link);
export const orpc = createTanstackQueryUtils(client);
export const ORPCContext = createContext<ORPCReactUtils | undefined>(undefined);
export function useORPC(): ORPCReactUtils {
const orpc = useContext(ORPCContext);
if (!orpc) {
throw new Error("ORPCContext is not set up properly");
}
return orpc;
}