dioxus/examples/tasks.rs

30 lines
587 B
Rust
Raw Normal View History

2021-11-10 22:09:52 +00:00
//! Example: README.md showcase
//!
//! The example from the README.md.
2021-11-15 14:49:01 +00:00
use std::time::Duration;
2021-11-10 22:09:52 +00:00
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(app);
2021-11-10 22:09:52 +00:00
}
fn app(cx: Scope<()>) -> Element {
let mut count = use_state(&cx, || 0);
2021-11-10 22:09:52 +00:00
2021-12-26 19:22:30 +00:00
cx.push_future(|| async move {
2021-11-15 14:49:01 +00:00
tokio::time::sleep(Duration::from_millis(100)).await;
count += 1;
2021-11-10 22:09:52 +00:00
});
cx.render(rsx! {
div {
h1 { "High-Five counter: {count}" }
button {
onclick: move |_| count +=1 ,
"Click me!"
}
2021-11-10 22:09:52 +00:00
}
})
}