fermi 0.4.3

Global state management for Dioxus
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use crate::{use_atom_root, Writable};
use dioxus_core::ScopeState;
use std::rc::Rc;

#[must_use]
pub fn use_set<T: 'static>(cx: &ScopeState, f: impl Writable<T>) -> &Rc<dyn Fn(T)> {
    let root = use_atom_root(cx);
    cx.use_hook(|| {
        let id = f.unique_id();
        let root = root.clone();
        root.initialize(f);
        Rc::new(move |new| root.set(id, new)) as Rc<dyn Fn(T)>
    })
}