tasks.rs 750 B

1234567891011121314151617181920212223242526272829303132333435
  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, move || {
  12. let count = UseState::for_async(&count);
  13. // for_async![count];
  14. async move {
  15. // loop {
  16. // tokio::time::sleep(Duration::from_millis(1000)).await;
  17. // count += 1;
  18. // }
  19. }
  20. });
  21. cx.render(rsx! {
  22. div {
  23. h1 { "Current count: {count}" }
  24. button {
  25. onclick: move |_| count.set(0),
  26. "Reset the count"
  27. }
  28. }
  29. })
  30. }