tasks.rs 689 B

123456789101112131415161718192021222324252627282930313233
  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(cx: Scope) -> Element {
  10. let count = use_state(&cx, || 0);
  11. use_future(&cx, || {
  12. for_async![count];
  13. async move {
  14. while let _ = tokio::time::sleep(Duration::from_millis(1000)).await {
  15. *count.modify() += 1;
  16. }
  17. }
  18. });
  19. cx.render(rsx! {
  20. div {
  21. h1 { "High-Five counter: {count}" }
  22. button {
  23. onclick: move |_| *count.modify() += 1,
  24. "Click me!"
  25. }
  26. }
  27. })
  28. }