Skip to main content

composable

Attribute Macro composable 

Source
#[composable]
Expand description

Turns a function into a composable.

ⓘ
#[composable]
fn Greeting(name: String) {
    let clicks = remember(|| mutable_state_of(0));
    Text(format!("Hello, {name}: {}", clicks.get()));
    Button("Again").on_click(move || clicks.update(|count| *count += 1));
}

#[composable(nonrestartable)] keeps the groups and the skipping but never re-runs the function on its own: a state it reads re-runs its caller instead. That is what an associated function needs, because the runtime re-runs a function by calling it by its bare name.