Files
dioxus/packages/fermi/src/hooks/init_atom_root.rs
T
2022-02-17 10:38:51 -05:00

12 lines
347 B
Rust

use crate::AtomRoot;
use dioxus_core::ScopeState;
use std::rc::Rc;
// Initializes the atom root and retuns it;
pub fn use_init_atom_root(cx: &ScopeState) -> &Rc<AtomRoot> {
cx.use_hook(|_| match cx.consume_context::<AtomRoot>() {
Some(ctx) => ctx,
None => cx.provide_context(AtomRoot::new(cx.schedule_update_any())),
})
}