Function: createTRPCProxyClient()
On this page
Call Signature
createTRPCProxyClient<
TRouter,TLinks>(opts):TRPCClient<TRouter,inferLinksContext<TLinks>>
Defined in: packages/client/src/createTRPCClient.ts:250
Creates a typed client for a router. Pass the router's type with
routerType, and the links that send its calls. What the links declare
types each call's context.
Type Parameters
| Type Parameter | Default type |
|---|---|
TRouter extends AnyRouter | - |
TLinks extends readonly TRPCLink<TRouter, any>[] | TRPCLink<TRouter>[] |
Parameters
| Parameter | Type |
|---|---|
opts | CreateTRPCClientWithRouterOptions<TRouter, TLinks> |
Returns
TRPCClient<TRouter, inferLinksContext<TLinks>>
Example
const client = createTRPCClient({
router: routerType<AppRouter>(),
links: [retryLink({ retry: () => false }), httpBatchLink({ url })],
});
const post = await client.post.byId.query(
{ id: '1' },
{ context: { retry: (opts) => opts.attempts <= 3 } },
);See
https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
Call Signature
createTRPCProxyClient<
TRouter>(opts):TRPCClient<TRouter>
Defined in: packages/client/src/createTRPCClient.ts:273
Creates a typed client for a router. Pass the router's type, and the links that send its calls.
Type Parameters
| Type Parameter |
|---|
TRouter extends AnyRouter |
Parameters
| Parameter | Type |
|---|---|
opts | CreateTRPCClientOptions<TRouter> |
Returns
TRPCClient<TRouter>
Example
const client = createTRPCClient<AppRouter>({
links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
});
const post = await client.post.byId.query({ id: '1' });See
https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
Deprecated
Pass the router's type as router: routerType<AppRouter>()
instead of a type argument, so the links can type each call's context.
The type argument form is removed in v12.