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

#1373 in WebAssembly

Download history 635/week @ 2024-01-22 667/week @ 2024-01-29 696/week @ 2024-02-05 593/week @ 2024-02-12 497/week @ 2024-02-19 735/week @ 2024-02-26 612/week @ 2024-03-04 702/week @ 2024-03-11 792/week @ 2024-03-18 939/week @ 2024-03-25 787/week @ 2024-04-01 430/week @ 2024-04-08 786/week @ 2024-04-15 673/week @ 2024-04-22 834/week @ 2024-04-29 727/week @ 2024-05-06

3,066 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
~28K SLoC