DynamicLink
DynamicLink lets you dynamically choose between different oRPC's links based on your client context. This capability enables flexible routing of RPC requests.
Example
This example shows how the client dynamically selects between two RPCLink instances based on the client context: one dedicated to cached requests and another for non-cached requests.
ts
import { , } from '@orpc/client'
interface ClientContext {
?: boolean
}
const = new ({
: 'https://cache.example.com/rpc',
})
const = new ({
: 'https://example.com/rpc',
})
const = new <ClientContext>((, , ) => {
if (.?.) {
return
}
return
})
const : <typeof , ClientContext> = ()INFO
Any oRPC's link is supported, not strictly limited to RPCLink.
