This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index at /llms.txt, or add .md to any page's URL.
State, derives, and actions
A state is stored. A derive is a computed expression over its dependencies.
Prefer a derive when a value can be calculated from existing data; there is no
reason to keep a second mutable copy of a filtered list or a display label.
text
state query = ""
derive visible = items.filter(item => item.title.includes(query))
action search(value: string)
query = value
Components may own states, derives and actions. A root or a child at a bounded
use may also own resources, mutations and tasks, each for its instance's lifetime.
Data-sized list rows receive shared data and actions through props. State initializers read props,
injects and earlier states only: they run before any resource answers or
derive is computed. Derives can be declared in dependency order
or another order, but their dependency graph must be acyclic.
An action's state reads observe the state at its start. Its writes land together.
This is different from a sequence of imperative assignments in JavaScript:
contract
component Snapshot
state count = 0
state observed = 0
action step
count = count + 1
let before = count
observed = before
view
button press=step testId="step"
text `${count}/${observed}` testId="value"
After the first press, the text is 1/0. The local before saw the old count,
and the compiler warns of the read (analyze-read-after-assign). To reuse a newly
computed value, compute it once first:
text
action step
let next = count + 1
count = next
observed = next
let is immutable, belongs to its block, and is visible to following statements
and nested blocks. It cannot shadow an existing visible name, be reassigned, or
be read before its declaration. Separate branches may each declare their own
local of the same name. Locals do not become application state.
Actions support assignments to their own states and mutations, let, send,
refresh, host commands, calls of actions, if/else, and option match
blocks. They have no loops, return, or await. An action calls another action
of its component, an action prop or an injected action as a statement:
arrive(path) runs arrive's statements right there, in the same commit, and
they too read the state the action started with. So a helper does not see what
its caller assigned before the call; the compiler warns of such a read
(analyze-read-after-assign) and asks for the value to be passed
(arrive(next)). A name that is a host command, such as focus, stays the command, and calling an action, prop or inject that
shares a host command's name is refused: rename it. A call returns nothing: share calculations through
fn. The compiler infers the state an action writes, through its calls. Do not
write a writes clause.
Is this helpful
Last updated November 30, 2026