use_ref.rs 531 B

12345678910111213141516171819202122232425
  1. use std::collections::HashMap;
  2. use dioxus::prelude::*;
  3. fn main() {}
  4. fn app(cx: Scope) -> Element {
  5. let val = use_ref(&cx, || HashMap::<u32, String>::new());
  6. {
  7. // Pull the value out locally
  8. let p = val.read();
  9. // to get an &HashMap we have to "reborrow" through the RefCell
  10. // Be careful: passing this into children might cause a double borrow of the RefCell and a panic
  11. let g = &*p;
  12. dbg!(g);
  13. }
  14. cx.render(rsx! {
  15. div {
  16. "hi"
  17. }
  18. })
  19. }