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() {
|
2024-01-16 14:42:16 +00:00
|
|
|
launch(app);
|
2021-11-10 22:09:52 +00:00
|
|
|
}
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
2024-01-14 05:12:21 +00:00
|
|
|
let mut count = use_signal(|| 0);
|
2021-11-10 22:09:52 +00:00
|
|
|
|
2024-01-15 19:54:17 +00:00
|
|
|
use_future(move || async move {
|
2024-01-14 05:12:21 +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
|
|
|
});
|
|
|
|
|
2024-01-14 05:12:21 +00:00
|
|
|
rsx! {
|
2021-11-10 22:09:52 +00:00
|
|
|
div {
|
2022-01-03 05:42:17 +00:00
|
|
|
h1 { "Current count: {count}" }
|
2021-12-25 22:18:05 +00:00
|
|
|
button {
|
2022-03-01 07:50:03 +00:00
|
|
|
onclick: move |_| count.set(0),
|
2022-01-03 05:42:17 +00:00
|
|
|
"Reset the count"
|
2021-12-25 22:18:05 +00:00
|
|
|
}
|
2021-11-10 22:09:52 +00:00
|
|
|
}
|
2024-01-14 05:12:21 +00:00
|
|
|
}
|
2021-12-25 22:18:05 +00:00
|
|
|
}
|