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
- Zero-boilerplate hooks:
use_app_store()anduse_app_store_shallow() - Async Support: Mutations can be
asyncfunctions
Quick Start
use ;
// 1. Define your store
// 2. Define mutations
// 3. Use in components
API Reference
Store Macro: #[yewstand_store]
Automatically generates:
use_app_store()- Full store hookuse_app_store_shallow(|store| value)- Shallow selector hookupdate_store(|store| {...})- Functional updater- Global store infrastructure
Requirements: Store must implement Default, Clone, PartialEq
Mutations Macro: #[yewstand_mutations]
Transform functions like this:
Into callable methods:
set_count; // Updates global store automatically
Pattern: (state: AppStore, args...) -> AppStore
Examples
See the counter example for a complete working demo with:
- Full store subscription (
FullStorecomponent) - Shallow selector (
CountOnlycomponent) - Functional updates (
update_store) - Generated mutations (
AppStore::set_count)