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

#19 in #redux

Download history 482/week @ 2024-07-23 715/week @ 2024-07-30 973/week @ 2024-08-06 1015/week @ 2024-08-13 926/week @ 2024-08-20 1266/week @ 2024-08-27 1254/week @ 2024-09-03 678/week @ 2024-09-10 629/week @ 2024-09-17 849/week @ 2024-09-24 452/week @ 2024-10-01 422/week @ 2024-10-08 594/week @ 2024-10-15 679/week @ 2024-10-22 568/week @ 2024-10-29 632/week @ 2024-11-05

2,604 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–1.1MB
~24K SLoC