tRPC + AppRouter without reactQuery

hi everyone how can i host trpc on next.js and use trpc on server components without using react query.
1 Reply
korgko
korgko2y ago
// client/trpc.ts
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from './server';

export const trpc = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: SERVER_URL,
}),
],
});
// client/trpc.ts
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from './server';

export const trpc = createTRPCProxyClient<AppRouter>({
links: [
httpBatchLink({
url: SERVER_URL,
}),
],
});
// client/someFileYouWantToCall.ts
import { trpc } from './trpc'

const greeting = await trpc.getGreeting.query({name: "Korg"});
const createdUser = await trpc.userCreate.mutate({ name: 'Korg' });
// client/someFileYouWantToCall.ts
import { trpc } from './trpc'

const greeting = await trpc.getGreeting.query({name: "Korg"});
const createdUser = await trpc.userCreate.mutate({ name: 'Korg' });
You can read more about it here: https://trpc.io/docs/quickstart
Quickstart | tRPC
Learn how to quickly get started and setup tRPC
Want results from more Discord servers?
Add your server