| Crates.io | yewstand |
| lib.rs | yewstand |
| version | 0.1.0 |
| created_at | 2026-01-11 13:46:19.787027+00 |
| updated_at | 2026-01-11 13:46:19.787027+00 |
| description | Zustand-inspired state management for Yew. |
| homepage | |
| repository | https://codeberg.org/00030/yewstand |
| max_upload_size | |
| id | 2035832 |
| size | 39,210 |
Zustand-inspired state management for Yew - Simple, declarative global stores using Rust macros.
use_app_store() and use_app_store_shallow()async functionscargo add yew --features="csr"
cargo add yewstand
use yewstand::{yewstand_store, yewstand_mutations};
// 1. Define your store
#[derive(Default, Clone, PartialEq)]
#[yewstand_store]
pub struct AppStore {
pub count: i32,
pub name: String,
}
// 2. Define mutations
#[yewstand_mutations]
impl AppStore {
pub fn set_count(state: AppStore, value: i32) -> AppStore {
AppStore { count: value, ..state }
}
pub async fn load_count(state: AppStore, id: String) -> AppStore {
let count = get_count_from_backend().await;
AppStore { count, ..state }
}
}
// 3. Use in components
#[function_component(App)]
fn app() -> Html {
let store = use_app_store(); // Full store subscription
let count = *use_app_store_shallow(|s| s.count); // Shallow selector
let onclick = {
Callback::from(|_| {
AppStore::set_count(42); // Updates global store automatically
})
};
html! {
<>
<p>{ format!("Count: {}", count) }</p>
<p>{ format!("Name: {}", store.name) }</p>
<button onclick={onclick}>{ "Set to 42" }</button>
</>
}
}
#[yewstand_store]Automatically generates:
use_app_store() - Full store hookuse_app_store_shallow(|store| value) - Shallow selector hookupdate_store(|store| {...}) - Functional updaterRequirements: Store must implement Default, Clone, PartialEq
#[yewstand_mutations]Transform functions like this:
pub fn set_count(state: AppStore, value: i32) -> AppStore {
AppStore { count: value, ..state }
}
Into callable methods:
AppStore::set_count(42); // Updates global store automatically
Pattern: (state: AppStore, args...) -> AppStore
See the counter example for a complete working demo with:
FullStore component)CountOnly component)update_store)AppStore::set_count)