1
0

use_ref.rs 481 B

123456789101112131415161718192021
  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. // Pull the value out locally
  7. let p = val.read();
  8. // to get an &HashMap we have to "reborrow" through the RefCell
  9. // Be careful: passing this into children might cause a double borrow of the RefCell and a panic
  10. let g = &*p;
  11. cx.render(rsx! {
  12. div {
  13. "hi"
  14. }
  15. })
  16. }