dioxus/examples/readme.rs

23 lines
701 B
Rust
Raw Normal View History

//! The example from the readme!
//!
//! This example demonstrates how to create a simple counter app with dioxus. The `Signal` type wraps inner values,
//! making them `Copy`, allowing them to be freely used in closures and async functions. `Signal` also provides
//! helper methods like AddAssign, SubAssign, toggle, etc, to make it easy to update the value without running
//! into lock issues.
use dioxus::prelude::*;
2021-12-29 21:28:28 -05:00
2021-07-06 12:13:00 -04:00
fn main() {
2024-01-20 00:11:55 -08:00
launch(app);
2021-07-06 12:13:00 -04:00
}
fn app() -> Element {
2024-01-13 21:12:21 -08:00
let mut count = use_signal(|| 0);
2021-07-06 12:13:00 -04:00
2024-01-16 13:18:46 -06:00
rsx! {
h1 { "High-Five counter: {count}" }
2022-03-05 17:07:34 -05:00
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
2024-01-13 21:12:21 -08:00
}
}