tasks.rs 545 B

12345678910111213141516171819202122232425262728
  1. //! Example: README.md showcase
  2. //!
  3. //! The example from the README.md.
  4. use dioxus::prelude::*;
  5. use std::time::Duration;
  6. fn main() {
  7. launch_desktop(app);
  8. }
  9. fn app() -> Element {
  10. let mut count = use_signal(|| 0);
  11. use_future(move || async move {
  12. loop {
  13. tokio::time::sleep(Duration::from_millis(1000)).await;
  14. count += 1;
  15. }
  16. });
  17. rsx! {
  18. div {
  19. h1 { "Current count: {count}" }
  20. button { onclick: move |_| count.set(0), "Reset the count" }
  21. }
  22. }
  23. }