Crate leptos_state

Crate leptos_state 

Source
Expand description

§Leptos State Management Library

A state management library for Leptos applications inspired by Zustand’s simplicity and XState’s state machine capabilities.

§Features

  • Store Management: Zustand-inspired stores with reactive updates
  • State Machines: XState-inspired finite state machines
  • Leptos Integration: First-class support for Leptos reactive primitives
  • TypeScript-like DX: Ergonomic APIs with strong type safety

§Quick Start

use leptos::*;
use leptos_state::*;

// Create a store
#[derive(Clone, PartialEq)]
struct AppState {
    count: i32,
}

create_store!(AppStore, AppState, AppState { count: 0 });

// Use in components
#[component]
fn Counter() -> impl IntoView {
    let (state, set_state) = use_store::<AppStore>();
     
    view! {
        <button on:click=move |_| set_state.update(|s| s.count += 1)>
            "Count: " {move || state.get().count}
        </button>
    }
}

Re-exports§

pub use store::create_computed;
pub use store::provide_store;
pub use store::use_store_slice;
pub use store::LoggerMiddleware;
pub use store::MiddlewareChain;
pub use store::Store;
pub use store::StoreContext;
pub use store::StoreSlice;
pub use store::ValidationMiddleware;
pub use machine::Machine;
pub use machine::MachineBuilder;
pub use machine::MachineState;
pub use machine::StateMachine;
pub use hooks::use_machine;
pub use hooks::use_machine;
pub use hooks::use_machine_history;
pub use hooks::use_store;
pub use hooks::use_store;
pub use utils::LogLevel;
pub use utils::StateError;
pub use utils::StateResult;
pub use compat::*;

Modules§

compat
Compatibility Layer
hooks
Leptos integration hooks for stores and state machines
machine
State machine implementation inspired by XState
store
Store implementation inspired by Zustand
utils
Utility types and functions

Macros§

create_store
Macro for creating store implementations
property
Macro for creating properties
select_field
Macro for creating field selectors
test_case
Macro for creating test cases