2021-11-10 22:09:52 +00:00
|
|
|
//! Example: README.md showcase
|
|
|
|
//!
|
|
|
|
//! The example from the README.md.
|
|
|
|
|
2021-12-30 02:28:28 +00:00
|
|
|
use dioxus::prelude::*;
|
2021-11-15 14:49:01 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2021-11-10 22:09:52 +00:00
|
|
|
fn main() {
|
2021-12-25 22:18:05 +00:00
|
|
|
dioxus::desktop::launch(app);
|
2021-11-10 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 02:28:28 +00:00
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
let count = use_state(&cx, || 0);
|
2021-11-10 22:09:52 +00:00
|
|
|
|
2021-12-30 02:28:28 +00:00
|
|
|
use_future(&cx, || {
|
|
|
|
for_async![count];
|
|
|
|
async move {
|
2021-12-30 08:14:47 +00:00
|
|
|
loop {
|
|
|
|
tokio::time::sleep(Duration::from_millis(1000)).await;
|
|
|
|
count += 1;
|
2021-12-30 02:28:28 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-10 22:09:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
|
|
|
h1 { "High-Five counter: {count}" }
|
2021-12-25 22:18:05 +00:00
|
|
|
button {
|
2021-12-30 02:28:28 +00:00
|
|
|
onclick: move |_| *count.modify() += 1,
|
2021-12-25 22:18:05 +00:00
|
|
|
"Click me!"
|
|
|
|
}
|
2021-11-10 22:09:52 +00:00
|
|
|
}
|
|
|
|
})
|
2021-12-25 22:18:05 +00:00
|
|
|
}
|