DynamicLink
DynamicLink lets you choose a link at runtime. Use it when different requests should be routed through different links.
Example
ts
import { createORPCClient, DynamicLink } from '@orpc/client'
interface ClientContext {
cache?: boolean
}
const cacheLink = new RPCLink({
origin: 'https://cache.example.com',
})
const noCacheLink = new RPCLink({
origin: 'https://example.com',
})
const link = new DynamicLink<ClientContext>((options, path, input) => {
if (options.context?.cache) {
return cacheLink
}
return noCacheLink
})
const client: RouterClient<typeof router, ClientContext> = createORPCClient(link)INFO
This example uses two RPC Link instances, but DynamicLink works with any other link.

