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

#1309 in WebAssembly

Download history 590/week @ 2023-12-13 427/week @ 2023-12-20 205/week @ 2023-12-27 517/week @ 2024-01-03 643/week @ 2024-01-10 478/week @ 2024-01-17 626/week @ 2024-01-24 746/week @ 2024-01-31 630/week @ 2024-02-07 541/week @ 2024-02-14 584/week @ 2024-02-21 703/week @ 2024-02-28 646/week @ 2024-03-06 661/week @ 2024-03-13 982/week @ 2024-03-20 752/week @ 2024-03-27

3,121 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.7–1.2MB
~26K SLoC