# Children: Content<T>

> Status: implemented are markup as HTML, components of the server, their results, `Response`
> going up, `Content<T>`, component values with a result, decorators with guards, wrappers that
> take the body and the request context, routes, and `rooklang/server`; the server of the site, `site/server/main.rk`, is written
> with them, and the guide has a section on them. The decisions are collected at the end of the
> document, together with what is not decided yet. Server markup, components and `rooklang/server`
> remain **experimental** in 1.x and may change between releases.

> This document builds on [components.md](https://github.com/QWERN-9876r/RookLang/blob/HEAD/docs/components.md): components, decorators, context,
> components as values. It describes only what is different on the server.

A component that wraps others, a middleware, decides whether they run at all. So the children of a
component of the server are lazy: they are rendered only when the component asks for them.

```go
comp Logger<T>(children Content<T>) T {
    const started = Date.now()
    defer console.log(`${@session.url.pathname}: ${Date.now() - started} ms`)
    return await children()
}
```

- **`Content<T>`** is a function without parameters that renders the children and gives their
  result, `T`. Calling it runs them; not calling it skips them, with all they would load.
- **`{children}` in markup** is `await children()`: the children go where it stands.
- **`Content` without an argument** is `Content<Html>`, so the components of the browser that take
  `children Content` mean the same on the server. A use without children gives `null` when they are
  called.
- **The children of `Content` are markup,** also a single component: `<Layout><Article /></Layout>`
  gives `Html`, and a `Response` of `Article` goes up when `Layout` calls them, also with
  `await children()`.
- **Type parameters of a component**, `comp Logger<T>(...)`, are new: they are written as for a
  function (see "Generics" in [spec.md](../../../reference/language/index.md)) and are inferred from the properties and the
  children of the tag, as those of a call are from its arguments:
  `<List items={[1, 2]} render={n => String(n)} />` of
  `comp List<T>(items T[], render func(T) string)` takes `T` from `items`, and `n` is a number.
  The type of `<Logger><Users /></Logger>` is `User[]`, that of `<Logger><Profile /></Logger>` is
  `Html | Response`, that of `<Logger><p>...</p></Logger>` is `Html`. One component among the
  children of `Content<T>` gives its own value; other children are markup.
- **The children are checked** against `Content<T>` of a type: `<Names><Users /></Names>` of
  `comp Names(children Content<string[]>)` is an error,
  `the children of <Names> give User[], but it takes Content<string[]>`.
- **Calling the children twice** renders them twice; that is allowed, as for any function.

