dioxus/examples/readme.rs

21 lines
464 B
Rust
Raw Normal View History

2021-07-06 12:13:00 -04:00
//! Example: README.md showcase
//!
2021-07-11 19:31:07 -04:00
//! The example from the README.md.
2021-07-06 12:13:00 -04:00
use dioxus::prelude::*;
2021-07-06 12:13:00 -04:00
fn main() {
2021-07-11 19:31:07 -04:00
dioxus::desktop::launch(App, |c| c);
2021-07-06 12:13:00 -04:00
}
2021-10-16 17:37:28 -04:00
static App: FC<()> = |(cx, props)| {
2021-07-08 23:25:27 -04:00
let mut count = use_state(cx, || 0);
2021-07-06 12:13:00 -04:00
cx.render(rsx! {
2021-07-08 23:25:27 -04:00
div {
2021-07-11 19:31:07 -04:00
h1 { "High-Five counter: {count}" }
2021-07-08 23:25:27 -04:00
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
}
2021-07-06 12:13:00 -04:00
})
2021-07-08 23:25:27 -04:00
};