Function fermi::hooks::use_atom_state
source · pub fn use_atom_state<T: 'static>(
cx: &ScopeState,
f: impl Writable<T>
) -> &AtomState<T>
Expand description
Store state between component renders.
Dioxus equivalent of AtomState, designed for Rust
The Dioxus version of AtomState
for state management inside components. It allows you to ergonomically store and
modify state between component renders. When the state is updated, the component will re-render.
ⓘ
static COUNT: Atom<u32> = |_| 0;
fn Example(cx: Scope) -> Element {
let mut count = use_atom_state(cx, &COUNT);
cx.render(rsx! {
div {
h1 { "Count: {count}" }
button { onclick: move |_| count += 1, "Increment" }
button { onclick: move |_| count -= 1, "Decrement" }
}
))
}