hooks_use_ref.rs 448 B

12345678910111213141516171819202122
  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 list = use_ref(cx, Vec::new);
  9. cx.render(rsx!(
  10. p { "Current list: {list.read():?}" }
  11. button {
  12. onclick: move |event| {
  13. list.with_mut(|list| list.push(event));
  14. },
  15. "Click me!"
  16. }
  17. ))
  18. }
  19. // ANCHOR_END: component