dioxus/examples/readme.rs

22 lines
481 B
Rust
Raw Normal View History

2021-07-06 16:13:00 +00:00
//! Example: README.md showcase
//!
2021-07-11 23:31:07 +00:00
//! The example from the README.md.
2021-07-06 16:13:00 +00:00
use dioxus::prelude::*;
2021-12-30 02:28:28 +00:00
2021-07-06 16:13:00 +00:00
fn main() {
dioxus::desktop::launch(app);
2021-07-06 16:13:00 +00:00
}
fn app(cx: Scope) -> Element {
2022-01-26 02:41:40 +00:00
let (count, set_count) = use_state(&cx, || 0);
2021-07-06 16:13:00 +00:00
cx.render(rsx! {
2021-07-09 03:25:27 +00:00
div {
2021-07-11 23:31:07 +00:00
h1 { "High-Five counter: {count}" }
2022-01-26 02:41:40 +00:00
button { onclick: move |_| set_count(count + 1), "Up high!" }
button { onclick: move |_| set_count(count - 1), "Down low!" }
2021-07-09 03:25:27 +00:00
}
2021-07-06 16:13:00 +00:00
})
}