yewdux-macros

Crates.ioyewdux-macros
lib.rsyewdux-macros
version0.10.0
sourcesrc
created_at2022-08-19 01:09:07.283568
updated_at2023-12-19 02:53:00.462471
descriptionErgonomic state management for Yew applications
homepage
repositoryhttps://github.com/yewdux/yewdux
max_upload_size
id648457
size5,889
Noah Corona (intendednull)

documentation

README

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();
}
Commit count: 272

cargo fmt