hooks_counter.rs 413 B

123456789101112131415161718
  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. let mut count = use_state(&cx, || 0);
  9. cx.render(rsx!(
  10. h1 { "High-Five counter: {count}" }
  11. button { onclick: move |_| count += 1, "Up high!" }
  12. button { onclick: move |_| count -= 1, "Down low!" }
  13. ))
  14. }
  15. // ANCHOR_END: component