Crates.io | fermi |
lib.rs | fermi |
version | 0.4.3 |
source | src |
created_at | 2021-12-14 19:56:24.937523 |
updated_at | 2023-12-07 01:42:16.865538 |
description | Global state management for Dioxus |
homepage | https://dioxuslabs.com |
repository | https://github.com/DioxusLabs/dioxus/ |
max_upload_size | |
id | 497890 |
size | 29,815 |
Atom-based global state management solution for Dioxus
Fermi is a global state management solution for Dioxus that's as easy as use_state
.
Inspired by atom-based state management solutions, all state in Fermi starts as an atom
:
static NAME: Atom<&str> = Atom(|_| "Dioxus");
From anywhere in our app, we can read the value of our atom:
fn NameCard(cx: Scope) -> Element {
let name = use_read(cx, &NAME);
cx.render(rsx!{ h1 { "Hello, {name}"} })
}
We can also set the value of our atom, also from anywhere in our app:
fn NameCard(cx: Scope) -> Element {
let set_name = use_set(cx, &NAME);
cx.render(rsx!{
button {
onclick: move |_| set_name("Fermi"),
"Set name to fermi"
}
})
}
If needed, we can update the atom's value, based on itself:
static COUNT: Atom<i32> = Atom(|_| 0);
fn Counter(cx: Scope) -> Element {
let mut count = use_atom_state(cx, &COUNT);
cx.render(rsx!{
p {
"{count}"
}
button {
onclick: move |_| count += 1,
"Increment counter"
}
})
}
It's that simple!
Fermi is currently under construction, so you have to use the master
branch to get started.
[dependencies]
fermi = { git = "https://github.com/dioxuslabs/dioxus" }
The examples here use Dioxus Desktop to showcase their functionality. To run an example, use
$ cargo run --example fermi
Broadly our feature set required to be released includes:
Clone
)