Function: splitLink()
On this page
Call Signature
splitLink<
TRouter,TTrue,TFalse>(opts):SplitLink<TRouter,TTrue,TFalse,AugmentedOperationContext>
Defined in: packages/client/dist/splitLink-BGLTgm1a.d.mts:43
Sends each operation down one of two link chains, based on condition.
Calls take the context both chains read. Give context defaults to
declare the fields condition reads; without them, condition reads
the fields added to OperationContext.
Type Parameters
| Type Parameter | Default type |
|---|---|
TRouter extends AnyRouter | AnyRouter |
TTrue extends SplitLinkBranch<TRouter> | SplitLinkBranch<TRouter> |
TFalse extends SplitLinkBranch<TRouter> | SplitLinkBranch<TRouter> |
Parameters
| Parameter | Type |
|---|---|
opts | SplitLinkOptions<TRouter, TTrue, TFalse, OperationContext> & object |
Returns
SplitLink<TRouter, TTrue, TFalse, AugmentedOperationContext>
Example
splitLink({
context: { skipBatch: false },
condition: (op) => op.context.skipBatch,
true: httpLink({ url }),
false: httpBatchLink({ url }),
})See
https://trpc.io/docs/client/links/splitLink
Call Signature
splitLink<
TRouter,TTrue,TFalse,TContext>(opts):SplitLink<TRouter,TTrue,TFalse,TContext>
Defined in: packages/client/dist/splitLink-BGLTgm1a.d.mts:46
Sends each operation down one of two link chains, based on condition.
Calls take the context both chains read. Give context defaults to
declare the fields condition reads; without them, condition reads
the fields added to OperationContext.
Type Parameters
| Type Parameter |
|---|
TRouter extends AnyRouter |
TTrue extends SplitLinkBranch<TRouter> |
TFalse extends SplitLinkBranch<TRouter> |
TContext extends object |
Parameters
| Parameter | Type |
|---|---|
opts | SplitLinkOptions<TRouter, TTrue, TFalse, TContext> & object |
Returns
SplitLink<TRouter, TTrue, TFalse, TContext>
Example
splitLink({
context: { skipBatch: false },
condition: (op) => op.context.skipBatch,
true: httpLink({ url }),
false: httpBatchLink({ url }),
})