hooks_use_ref.rs 497 B

1234567891011121314151617181920212223
  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. let list_formatted = format!("{:?}", *list.read());
  10. cx.render(rsx!(
  11. p { "Current list: {list_formatted}" }
  12. button {
  13. onclick: move |event| {
  14. list.write().push(event)
  15. },
  16. "Click me!"
  17. }
  18. ))
  19. }
  20. // ANCHOR_END: component