Function: lazy()
On this page
lazy<
TRouter>(importRouter):Lazy<NoInfer<TRouter>>
Defined in: packages/server/src/unstable-core-do-not-import/router.ts:125
Loads a router on its first call instead of at startup, which can make cold starts faster. Pass a function that imports the router, or a module whose only export is the router.
Type Parameters
| Type Parameter |
|---|
TRouter extends AnyTRPCRouter |
Parameters
| Parameter | Type |
|---|---|
importRouter | () => Promise<TRouter | {}> |
Returns
Lazy<NoInfer<TRouter>>
Example
const appRouter = router({
slow: lazy(() => import('./slow.js').then((m) => m.slowRouter)),
});