1
0

signals.rs 625 B

123456789101112131415161718192021222324252627
  1. use dioxus::prelude::*;
  2. use std::time::Duration;
  3. fn main() {
  4. dioxus_desktop::launch(app);
  5. }
  6. fn app(cx: Scope) -> Element {
  7. let mut count = dioxus_signals::use_signal(cx, || 0);
  8. use_future!(cx, || async move {
  9. loop {
  10. count += 1;
  11. tokio::time::sleep(Duration::from_millis(400)).await;
  12. }
  13. });
  14. cx.render(rsx! {
  15. h1 { "High-Five counter: {count}" }
  16. button { onclick: move |_| count += 1, "Up high!" }
  17. button { onclick: move |_| count -= 1, "Down low!" }
  18. if count.value() > 5 {
  19. rsx!{ h2 { "High five!" } }
  20. }
  21. })
  22. }