1
0

hooks_counter.rs 771 B

12345678910111213141516171819202122232425262728293031
  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. // count will be initialized to 0 the first time the component is rendered
  9. let mut count = use_state(cx, || 0);
  10. cx.render(rsx!(
  11. h1 { "High-Five counter: {count}" }
  12. button {
  13. onclick: move |_| {
  14. // changing the count will cause the component to re-render
  15. count += 1
  16. },
  17. "Up high!"
  18. }
  19. button {
  20. onclick: move |_| {
  21. // changing the count will cause the component to re-render
  22. count -= 1
  23. },
  24. "Down low!"
  25. }
  26. ))
  27. }
  28. // ANCHOR_END: component