brightness on every drag, and the Muted text responds through {{ brightness }} interpolation. No action needed.
SetState gives you explicit control when auto-binding isn’t enough: setting literal values, computing new state from old, or wiring up non-form elements like buttons.
Drag the slider — the text updates instantly. set_initial_state(brightness=50) seeds the starting value; the name prop handles the rest.
Event Capture (the Default)
When you writeSetState("brightness") without a second argument, it defaults to {{ $event }} — the value from the triggering interaction. What $event means depends on the component:
| Component | $event value |
|---|---|
| Slider | Current slider position (number) |
| Input / Textarea | Current text value (string) |
| Checkbox / Switch | Checked state (boolean) |
| Select | Selected option value (string) |
| RadioGroup | Selected radio value (string) |
| Button | undefined |
SetState("key") is all you need for form controls — it automatically captures the right value.
Explicit Values
Pass a second argument to set a specific value instead of capturing the event. Click the buttons below to change the color: The div’scss_class uses {{ color }} interpolation, so clicking a button swaps the Tailwind class and the color changes instantly.
Resetting State
Use explicit values to build reset buttons:Toggle State
ToggleState flips a boolean — True becomes False, False becomes True. It’s the shorthand for show/hide patterns, expand/collapse, and on/off toggles.
ToggleState pairs naturally with If — toggle the state variable, and the conditional block shows or hides the content. Click the button above to see it in action.
Multiple Independent Toggles
EachToggleState key is independent, so you can manage multiple visibility states:
Initial State
Seed state with initial values usingset_initial_state():
Initial State
name="volume") automatically sync with state — the slider starts at 75, the switch starts off. For tools, you can also set initial state via AppResult.state:
AppResult Initial State
API Reference
ToggleState Parameters
State variable name to toggle. Can be passed as a positional argument.
Protocol Reference
SetState
ToggleState