mirror of
https://github.com/Rohithgilla12/data-peek
synced 2026-04-21 12:57:16 +00:00
24 lines
661 B
TypeScript
24 lines
661 B
TypeScript
import { createTRPCReact } from '@trpc/react-query'
|
|
import { createTRPCClient, httpBatchLink } from '@trpc/client'
|
|
import superjson from 'superjson'
|
|
import type { AppRouter } from '@/server/root'
|
|
|
|
export const trpc = createTRPCReact<AppRouter>()
|
|
|
|
function getBaseUrl() {
|
|
if (typeof window !== 'undefined') return ''
|
|
return `http://localhost:${process.env.PORT ?? 3001}`
|
|
}
|
|
|
|
export function createVanillaTRPCClient() {
|
|
return createTRPCClient<AppRouter>({
|
|
links: [
|
|
httpBatchLink({
|
|
url: `${getBaseUrl()}/api/trpc`,
|
|
transformer: superjson,
|
|
}),
|
|
],
|
|
})
|
|
}
|
|
|
|
export type TRPCClient = ReturnType<typeof createVanillaTRPCClient>
|