mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
24 lines
578 B
TypeScript
24 lines
578 B
TypeScript
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
import { browser } from "$app/environment";
|
|
import type { AppRouter } from "./router.server";
|
|
|
|
const createClient = (fetch: typeof globalThis.fetch) =>
|
|
createTRPCClient<AppRouter>({
|
|
links: [
|
|
httpBatchLink({
|
|
url: "/trpc",
|
|
fetch,
|
|
}),
|
|
],
|
|
});
|
|
|
|
let browserClient: ReturnType<typeof createClient>;
|
|
|
|
export const useTRPC = (fetch = globalThis.fetch) => {
|
|
const client = browserClient ?? createClient(fetch);
|
|
if (browser) {
|
|
browserClient ??= client;
|
|
}
|
|
return client;
|
|
};
|