Files
dioxus/examples/02-building-ui/counter.rs
T
Jonathan Kelley cd54f5953b update the dioxus cratesio readme, add many more examples (#5501)
* update the dioxus cratesio readme

* fix example

* fix header

* add a bunch more examples
2026-04-21 17:07:48 -07:00

23 lines
654 B
Rust

//! The classic counter — the "hello world" of reactive UI.
//!
//! `use_signal` creates a reactive value. Whenever the signal changes, any part of the UI
//! that reads it will re-render automatically. Signals are copy-cheap, so you can freely
//! move them into event handlers and closures.
use dioxus::prelude::*;
fn main() {
dioxus::launch(app);
}
fn app() -> Element {
let mut count = use_signal(|| 0);
rsx! {
h1 { "Count: {count}" }
button { onclick: move |_| count += 1, "Increment" }
button { onclick: move |_| count -= 1, "Decrement" }
button { onclick: move |_| count.set(0), "Reset" }
}
}