task.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. use dioxus::prelude::*;
  2. fn main() {
  3. rink::launch(app);
  4. }
  5. fn app(cx: Scope) -> Element {
  6. let (count, set_count) = use_state(&cx, || 0);
  7. use_future(&cx, move || {
  8. let set_count = set_count.to_owned();
  9. let update = cx.schedule_update();
  10. async move {
  11. loop {
  12. set_count.with_mut(|f| *f += 1);
  13. tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
  14. update();
  15. }
  16. }
  17. });
  18. cx.render(rsx! {
  19. div { width: "100%",
  20. div { width: "50%", height: "5px", background_color: "blue", justify_content: "center", align_items: "center",
  21. "Hello {count}!"
  22. }
  23. div { width: "50%", height: "10px", background_color: "red", justify_content: "center", align_items: "center",
  24. "Hello {count}!"
  25. }
  26. }
  27. })
  28. }
  29. // use_future(&cx, || {
  30. // let set_count = count.setter();
  31. // let mut mycount = 0;
  32. // let update = cx.schedule_update();
  33. // async move {
  34. // loop {
  35. // tokio::time::sleep(std::time::Duration::from_millis(100)).await;
  36. // mycount += 1;
  37. // set_count(mycount);
  38. // update();
  39. // }
  40. // }
  41. // });