Crate yewstand

Crate yewstand 

Source
Expand description

Yewstand

Zustand-inspired state management for Yew - Simple, declarative global stores using Rust macros.

§Features

  • Global Store: Single source of truth with automatic React-like re-renders
  • Shallow Selectors: Subscribe only to specific fields for optimal performance
  • Mutation Macros: Generate store-updating methods from simple functions

§Quick Start

cargo add yew --features="csr"
cargo add yewstand
use yew::prelude::*;
use yewstand::{yewstand_store, yewstand_mutations};

#[derive(Default, Clone, PartialEq)]
#[yewstand_store]  
pub struct AppStore {
    pub count: i32,
}

#[yewstand_mutations]
impl AppStore {
    pub fn set_count(state: AppStore, value: i32) -> AppStore {
        AppStore { count: value, ..state }
    }
}

// Usage in components
#[function_component(ExampleComponent)]
fn example_component() -> Html {
    let count = *use_app_store_shallow(|s| s.count);
    AppStore::set_count(42); // Updates global store

    html! {
        <div>
            <p>{ format!("Count: {}", count) }</p>
        </div>
    }
}

Attribute Macros§

yewstand_mutations
Mutation macro - transforms state functions into store updaters.
yewstand_store
Store macro - generates hooks and global store infrastructure.