tasks.rs 597 B

12345678910111213141516171819202122232425262728293031
  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. dioxus_desktop::launch(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 {
  21. onclick: move |_| count.set(0),
  22. "Reset the count"
  23. }
  24. }
  25. }
  26. }