3 unstable releases
0.10.0 | Dec 19, 2023 |
---|---|
0.9.4 | Oct 10, 2023 |
0.9.3 | Jun 1, 2023 |
#901 in WebAssembly
7KB
125 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
~12–21MB
~284K SLoC