:title
COMPONENT

:sig
function COMPONENT(props : dval)
function COMPONENT:NAME(props : dval)

:content
`COMPONENT` marks a function as a renderable fragment. Another unit reaches it with `component()` or `component_render()`; it is never routed to directly by a URL.

The handler receives `props : dval`, binds `request` implicitly, and returns nothing. Everything it `print`s becomes the fragment's output.

## Plain and named handlers

A file with a single fragment defines `COMPONENT`. Callers name just the file:

    component_render("lib/card.capy")

A file that holds several related fragments gives each one a name, and callers select it with a `:` suffix:

    component_render("lib/widgets.capy:CARD")

A caller inside that same file can use the bare suffix form, `component_render(":CARD")`, which resolves to the current file.

Names are matched exactly and are conventionally uppercase.

## Reading input

Caller-supplied props arrive through the `props` parameter. Read them through `string()`, `s64()`, and the other converters so a missing key has a defined value:

    var title := string(props.title, fallback: "Untitled")

Props are shared objects. Changes to their contents remain visible to the caller. Each nested component receives its own props argument. Application request keys stay shared.

## Lifecycle

The first time a unit is used in a request, its `ONCE` handler runs before the component handler. A component may render other components; each nested call resolves relative paths against its own file.

:errors
A caller that names a component Bearer cannot resolve gets a `500` status and a banner element in place of the fragment. The handler in this file never runs. Callers that treat a fragment as optional should guard with `length(component_resolve(name)) > 0`.

:example capy component
print(string(props.name, fallback: "guest"))

:example capy component read several props with defaults
var title := string(props.title, fallback: "Untitled")
var count := s64(props.count)
print("<article><h3>", title, "</h3><p>", count, "</p></article>")

:example capy component a fragment that nests another fragment
print("<section>")
component_render("/doc/examples/card.capy:CARD",
	title: string(props.title, fallback: "Untitled")
)
print("</section>")

:see-group
components

:see
handler/render
