hooks_counter_two_state.rs 664 B

123456789101112131415161718192021222324
  1. #![allow(non_snake_case)]
  2. use dioxus::prelude::*;
  3. fn main() {
  4. dioxus_desktop::launch(App);
  5. }
  6. // ANCHOR: component
  7. fn App(cx: Scope) -> Element {
  8. // ANCHOR: use_state_calls
  9. let mut count_a = use_state(&cx, || 0);
  10. let mut count_b = use_state(&cx, || 0);
  11. // ANCHOR_END: use_state_calls
  12. cx.render(rsx!(
  13. h1 { "Counter_a: {count_a}" }
  14. button { onclick: move |_| count_a += 1, "a++" }
  15. button { onclick: move |_| count_a -= 1, "a--" }
  16. h1 { "Counter_b: {count_b}" }
  17. button { onclick: move |_| count_b += 1, "b++" }
  18. button { onclick: move |_| count_b -= 1, "b--" }
  19. ))
  20. }
  21. // ANCHOR_END: component