1
0

clock.rs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. use dioxus_signals::{use_signal, Effect, Signal};
  4. fn main() {
  5. dioxus_desktop::launch(app);
  6. }
  7. fn app(cx: Scope) -> Element {
  8. let counts = use_signal(cx, || (0..100).map(Signal::new).collect::<Vec<_>>());
  9. cx.use_hook(|| {
  10. Effect::new(move || {
  11. println!("Counts: {:?}", counts);
  12. })
  13. });
  14. render! {
  15. for count in counts {
  16. Child {
  17. count: count,
  18. }
  19. }
  20. }
  21. }
  22. #[derive(Props, PartialEq)]
  23. struct ChildProps {
  24. count: Signal<u64>,
  25. }
  26. fn Child(cx: Scope<ChildProps>) -> Element {
  27. let count = cx.props.count;
  28. // use_future!(cx, || async move {
  29. // loop {
  30. // tokio::time::sleep(std::time::Duration::from_secs(count.value())).await;
  31. // *count.write() += 1;
  32. // }
  33. // });
  34. render! {
  35. div {
  36. "Child: {count}"
  37. button {
  38. onclick: move |_| {
  39. *count.write() += 1;
  40. },
  41. "Increase"
  42. }
  43. button {
  44. onclick: move |_| {
  45. *count.write() -= 1;
  46. },
  47. "Decrease"
  48. }
  49. }
  50. }
  51. }