Build a counter
A counter is a good first Fission recipe because it is small, interactive, and does not need app-wide domain state.
The count is local UI state owned by this widget identity, so it disappears when the counter is removed and does not have to live in GlobalState.
Full example
use fission::prelude::*;
fission_component! {
CounterApp<()> {
state { count: i32 = 0 }
}
view(counter, _state, cx) {
let tokens = &cx.view.env().theme.tokens;
} =>
Container(
Column(
gap: tokens.spacing.l,
children: [
Text("Counter").size(tokens.typography.heading1_size),
Text(counter.count.to_string()).size(tokens.typography.display_md_size),
Button(
child: Text("Increment"),
key: "increment",
on_press: reduce { counter.count += 1; },
)
.semantics_identifier("counter.increment"),
],
),
)
.padding_all(tokens.spacing.xl)
}
fn main() -> anyhow::Result<()> {
DesktopApp::<(), _>::new(CounterApp).run()
}
What matters
fission_component! defines a typed component and its widget tree together.
The state section makes count retained component state rather than app-wide GlobalState.
The inline on_press: reduce block keeps this one-component state transition beside the control that owns it.
The literal key gives the button a stable widget identity, while the semantic identifier makes it easy for tests and assistive technology to find.
Theme tokens provide spacing and typography rather than baking a second visual language into the example.
Use GlobalState when the value is part of your app model, persistence, routing, sync, or shared behavior. Use local widget state for temporary UI state like this counter, a local draft value, an open/closed flag, or a selected tab inside one component. The longer guide to this decision is State, handles, and providers. Run it
From the project directory, run:
cargo run
Press Increment. The number should change. The count belongs to this component instance, so removing the counter from the tree and adding it again creates a fresh count.