Function: createTRPCContext()
On this page
Call Signature
createTRPCContext<
TSource,TKeyPrefix>(opts):CreateTRPCContextResult<inferSourceRouter<TSource>,TKeyPrefixextendsFeatureFlags?TKeyPrefix<TKeyPrefix> :object,inferSourceLinkContext<TSource>,inferSourceClient<TSource>>
Defined in: Context.tsx:149
Creates a TRPCProvider and the useTRPC and useTRPCClient hooks.
Pass the router's type with routerType, or the client (or the function
that creates it) to type trpc.context from its links.
Type Parameters
| Type Parameter | Default type |
|---|---|
TSource extends TRPCContextSource | - |
TKeyPrefix extends boolean | FeatureFlags | false |
Parameters
| Parameter | Type |
|---|---|
opts | CreateTRPCContextOptions<TSource, TKeyPrefix extends FeatureFlags ? TKeyPrefix<TKeyPrefix>["keyPrefix"] : TKeyPrefix> |
Returns
CreateTRPCContextResult<inferSourceRouter<TSource>, TKeyPrefix extends FeatureFlags ? TKeyPrefix<TKeyPrefix> : object, inferSourceLinkContext<TSource>, inferSourceClient<TSource>>
Example
export const { TRPCProvider, useTRPC, useTRPCClient } = createTRPCContext({
router: routerType<AppRouter>(),
});
// or, with `trpc.context` typed from the links
const makeTRPCClient = () =>
createTRPCClient({ router: routerType<AppRouter>(), links });
export const { TRPCProvider, useTRPC } = createTRPCContext({
client: makeTRPCClient,
});See
https://trpc.io/docs/client/tanstack-react-query/setup#3a-set-up-the-trpc-context-provider
Call Signature
createTRPCContext<
TRouter,TFeatureFlags>():CreateTRPCContextResult<TRouter,TFeatureFlags>
Defined in: Context.tsx:176
Creates a TRPCProvider and the useTRPC and useTRPCClient hooks for
your router.
Type Parameters
| Type Parameter | Default type |
|---|---|
TRouter extends AnyRouter | - |
TFeatureFlags extends FeatureFlags | object |
Returns
CreateTRPCContextResult<TRouter, TFeatureFlags>
Example
export const { TRPCProvider, useTRPC, useTRPCClient } =
createTRPCContext<AppRouter>();See
https://trpc.io/docs/client/tanstack-react-query/setup#3a-set-up-the-trpc-context-provider