tasks.rs 585 B

1234567891011121314151617181920212223242526272829
  1. //! Example: README.md showcase
  2. //!
  3. //! The example from the README.md.
  4. use std::time::Duration;
  5. use dioxus::prelude::*;
  6. fn main() {
  7. dioxus::desktop::launch(app);
  8. }
  9. fn app(cx: Scope<()>) -> Element {
  10. let mut count = use_state(&cx, || 0);
  11. cx.push_task(|| async move {
  12. tokio::time::sleep(Duration::from_millis(100)).await;
  13. count += 1;
  14. });
  15. cx.render(rsx! {
  16. div {
  17. h1 { "High-Five counter: {count}" }
  18. button {
  19. onclick: move |_| count +=1 ,
  20. "Click me!"
  21. }
  22. }
  23. })
  24. }