#container

macro yewdux-macros

Ergonomic state management for Yew applications

9 releases

0.10.0 Dec 19, 2023
0.9.4 Oct 10, 2023
0.9.3 Jun 1, 2023
0.9.2 Feb 23, 2023
0.8.1 Aug 19, 2022

#392 in #container

Download history 585/week @ 2024-06-24 608/week @ 2024-07-01 432/week @ 2024-07-08 547/week @ 2024-07-15 555/week @ 2024-07-22 633/week @ 2024-07-29 877/week @ 2024-08-05 1106/week @ 2024-08-12 766/week @ 2024-08-19 1247/week @ 2024-08-26 1351/week @ 2024-09-02 790/week @ 2024-09-09 632/week @ 2024-09-16 861/week @ 2024-09-23 478/week @ 2024-09-30 327/week @ 2024-10-07

2,345 downloads per month
Used in 9 crates (via yewdux)

MIT/Apache

6KB
96 lines

Yewdux

Ergonomic state management for Yew applications.

See the book for more details.

Example

use yew::prelude::*;
use yewdux::prelude::*;

#[derive(Default, Clone, PartialEq, Store)]
struct State {
    count: u32,
}

#[function_component]
fn ViewCount() -> Html {
    let (state, _) = use_store::<State>();
    html!(state.count)
}

#[function_component]
fn IncrementCount() -> Html {
    let (_, dispatch) = use_store::<State>();
    let onclick = dispatch.reduce_mut_callback(|counter| counter.count += 1);

    html! {
        <button {onclick}>{"+1"}</button>
    }
}

#[function_component]
fn App() -> Html {
    html! {
        <>
        <ViewCount />
        <IncrementCount />
        </>
    }
}

fn main() {
    yew::Renderer::<App>::new().render();
}

Dependencies

~0.6–1MB
~24K SLoC