atom_root.rs 437 B

123456789101112
  1. use std::rc::Rc;
  2. use crate::AtomRoot;
  3. use dioxus_core::ScopeState;
  4. // Returns the atom root, initiaizing it at the root of the app if it does not exist.
  5. pub fn use_atom_root(cx: &ScopeState) -> &Rc<AtomRoot> {
  6. cx.use_hook(|| match cx.consume_context::<Rc<AtomRoot>>() {
  7. Some(root) => root,
  8. None => panic!("No atom root found in context. Did you forget to call use_init_atom_root at the top of your app?"),
  9. })
  10. }