function renderView
Since 0.6.0
renderView<P>(
ctx: IRequestContext,
component: Component<P>,
props: P
): Promise<HandlerResult>

Renders a view component with the given props and writes the result as the request's HTML response.

The engine is resolved per request from ctx.services, so a replacement provider registered under CAPABILITIES.VIEW is honored exactly like it is for the @Render branch.

Examples

Example 1

import { renderView } from '@setu-ts/view-plugin';

router.get('/users', (ctx) => renderView(ctx, UserList, { users }));

Type Parameters

The component's props bag

Parameters

ctx: IRequestContext

The current kernel request context

component: Component<P>

The view component to render

props: P

The props passed to the component

Return Type

Promise<HandlerResult>

The handler result carrying the text/html; charset=utf-8 body

Throws

Error

When no CAPABILITIES.VIEW provider is registered — register ViewPlugin (or any other provider of the token) first

ViewRenderError

When the component throws or returns a value with no string form

UnresolvedSuspenseError

When the tree holds a pending <Suspense> boundary

Usage

import { renderView } from "view-plugin/src/index.ts";