# Hooks on the server

> 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 server component calls a module-local hook with `const task = useTask(id)`. The
compiler inlines the hook at the call site in the async component function. The body may
`await`, use server markup and call other hooks. Each invocation gets its own `let` and
`const`; parameters are evaluated when the call is reached.

```go
async func loadTitle(id number) string {
    return `Task #${id}`
}

hook useTask(id number) {
    const title = await loadTitle(id)
    defer console.log("finished rendering task", id)
    return { title }
}

comp TaskRow(id number) {
    const task = useTask(id)
    return <li>{task.title}</li>
}
```

The record in the hook's final `return` exposes its local names. A hook's `defer` runs with the
component's other deferred calls when it returns or throws, in reverse registration order.
Use ordinary `let` and `const` for server data. Browser declarations such as `state`,
`derived`, `ref`, `mount` and `effect` cause the same errors as in a server component.

