6 releases (3 breaking)

0.4.3 Dec 7, 2023
0.4.0 Aug 1, 2023
0.3.0 Jan 7, 2023
0.2.1 May 3, 2022
0.1.0 Dec 14, 2021

#37 in #state-management

Download history 26/week @ 2024-11-15 74/week @ 2024-11-22 82/week @ 2024-11-29 160/week @ 2024-12-06 192/week @ 2024-12-13 54/week @ 2024-12-20 12/week @ 2024-12-27 74/week @ 2025-01-03 158/week @ 2025-01-10 139/week @ 2025-01-17 94/week @ 2025-01-24 196/week @ 2025-01-31 183/week @ 2025-02-07 150/week @ 2025-02-14 150/week @ 2025-02-21 99/week @ 2025-02-28

634 downloads per month
Used in 9 crates (4 directly)

MIT/Apache

415KB
7.5K SLoC

Fermi ⚛

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!

Installation

Fermi is currently under construction, so you have to use the master branch to get started.

[dependencies]
fermi = { git = "https://github.com/dioxuslabs/dioxus" }

Running examples

The examples here use Dioxus Desktop to showcase their functionality. To run an example, use

$ cargo run --example fermi

Features

Broadly our feature set required to be released includes:

  • Support for Atoms
  • Support for AtomRef (for values that aren't Clone)
  • Support for Atom Families
  • Support for memoized Selectors
  • Support for memoized SelectorFamilies
  • Support for UseFermiCallback for access to fermi from async

Dependencies

~3MB
~62K SLoC