2021-11-10 17:09:52 -05:00
|
|
|
//! Example: README.md showcase
|
|
|
|
//!
|
|
|
|
//! The example from the README.md.
|
|
|
|
|
2021-12-29 21:28:28 -05:00
|
|
|
use dioxus::prelude::*;
|
2021-11-15 09:49:01 -05:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2021-11-10 17:09:52 -05:00
|
|
|
fn main() {
|
2021-12-25 17:18:05 -05:00
|
|
|
dioxus::desktop::launch(app);
|
2021-11-10 17:09:52 -05:00
|
|
|
}
|
|
|
|
|
2021-12-29 21:28:28 -05:00
|
|
|
fn app(cx: Scope) -> Element {
|
|
|
|
let count = use_state(&cx, || 0);
|
2021-11-10 17:09:52 -05:00
|
|
|
|
2022-01-02 18:35:38 -05:00
|
|
|
use_future(&cx, move || {
|
|
|
|
let count = UseState::for_async(&count);
|
|
|
|
// for_async![count];
|
2021-12-29 21:28:28 -05:00
|
|
|
async move {
|
2022-01-02 18:35:38 -05:00
|
|
|
// loop {
|
|
|
|
// tokio::time::sleep(Duration::from_millis(1000)).await;
|
|
|
|
// count += 1;
|
|
|
|
// }
|
2021-12-29 21:28:28 -05:00
|
|
|
}
|
2021-11-10 17:09:52 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
cx.render(rsx! {
|
|
|
|
div {
|
2022-01-03 00:42:17 -05:00
|
|
|
h1 { "Current count: {count}" }
|
2021-12-25 17:18:05 -05:00
|
|
|
button {
|
2022-01-03 00:42:17 -05:00
|
|
|
onclick: move |_| count.set(0),
|
|
|
|
"Reset the count"
|
2021-12-25 17:18:05 -05:00
|
|
|
}
|
2021-11-10 17:09:52 -05:00
|
|
|
}
|
|
|
|
})
|
2021-12-25 17:18:05 -05:00
|
|
|
}
|