Crates.io | yewdux-utils |
lib.rs | yewdux-utils |
version | 0.10.0 |
source | src |
created_at | 2023-06-01 06:21:10.118226 |
updated_at | 2023-12-19 02:54:36.469042 |
description | Ergonomic state management for Yew applications |
homepage | |
repository | https://github.com/yewdux/yewdux-utils |
max_upload_size | |
id | 879486 |
size | 6,263 |
Ergonomic state management for Yew applications.
See the book for more details.
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();
}