Flux renders from a reactive signal graph. Every state declaration is a
signal, and an assignment inside a handler is the whole update: the UI
recomputes only the nodes that read the written signal. This guide gives
copy-paste patterns for the shapes you meet beyond the counter.
Declare local state
Section titled “Declare local state”Declare a signal at the top of a compo:
compo Counter state count: Int = 0 Column gap: 8.0 Text text: "tapped {count} times" Button text: "Increment", onPress: || { count = count + 1 }The $count: Int = 0 shorthand is equivalent — you meet it in the scaffold
and in examples/counter. Both forms create the same signal; pick one style
per codebase and keep it.
There is no separate setState. The assignment is the update, and the
assignment inside a handler propagates through the dependency graph before
the host reconciles the dirty set.
Derive values instead of storing them
Section titled “Derive values instead of storing them”A value computed from other signals should be derived, not stored — two
signals that can disagree are a bug you have not met yet. Declare it as a
read-only let computed from signals:
compo Cart state items: Int = 3 state price: Float = 9.99 let total: Float = items * price // recomputed when items or price change Column Text text: "Total: {total}"Derivation recomputes when a written signal reaches it, and only the leaves
that read total recompose.
Bind a text input both ways
Section titled “Bind a text input both ways”TextInput is controlled: bind the signal with $ and write the typed value
back in onChangeText:
compo Composer state draft: String = "" Column gap: 8.0 TextInput text: $draft, onChangeText: fn(v) { draft = v }, placeholder: "Say something" Button text: "Clear", onPress: || { draft = "" }The $draft binding keeps the field and the signal in lockstep, so the Clear
button empties the field by assigning the signal.
Share state across components
Section titled “Share state across components”Flux has no provider/context widget. For state shared across components, lift a store component above its consumers and thread values down as props:
compo SessionStore state token: Option[String] = None // actions are handlers that write the store's signals
compo App SessionStore // children read token/user via props threaded from hereKeep stores small and explicit — one store per domain (auth, cart, settings),
mounted at the root Router or Screen that needs it. The signal graph is
shared across the whole app, so a store mounted high is visible to everything
mounted beneath it.
Load async data through a capability
Section titled “Load async data through a capability”Handlers stay synchronous; async work goes through a capability call that
returns a result cell (Ready / Pending / Error). An async capability
leaves the cell Pending, and an injected resolver settles it when the
platform responds:
compo Profile state name: Option[String] = None Column gap: 8.0 Text text: name ?? "Loading..." Button text: "Load", onPress: || { // call the capability; the result cell settles and updates `name` }The ?? operator renders the fallback while the cell is pending. See
Capabilities for the call surface and permission
handling.
Pattern summary
Section titled “Pattern summary”- Local:
state(or$) plus assignment in a handler. - Computed: a
letderived from signals, never a second signal. - Shared: a store
compolifted above its consumers; values as props. - Input:
$bindingonTextInputplusonChangeText. - Async: capability call → result cell → signal update on resolve.
Next steps
Section titled “Next steps”- Navigation for multi-screen apps that share state.
- Host-authoritative state for the invariant that makes one tap cost one update, independent of tree size.
