Expand description

Overview

sycamore-state is a utility library for better state management using sycamore’s reactive primitives

the main features of this crate are the State derive macro and Rc/Ref Collection signal types

currently for lifetime management this crate uses widely [sycamore::reactive::create_signal_unsafe],\n if you think there are possible unsafe errors feel free to open an issue

Usage


#[derive(Debug, State, Clone)]
#[state(clone, eq, debug)] // available derive macros are: (clone, debug, eq, ord)
pub struct MyState<'a> {
    pub field_1: String,
    pub field_2: u32,
    #[state]
    pub field_3: MyInnerState<'a>,
    #[state]
    #[collection]
    pub state_collection: Vec<MyInnerState<'a>>
} // From this struct two reactive structs will be generated
  // for more info see the State docs

#[derive(Debug, State, Clone)]
#[state(clone, eq, debug)]
pub struct MyInnerState<'a> {
    pub field_1: i64,
    #[collection]
    pub collection: Vec<&'a str>
} // From this struct two reactive structs will be generated
  // for more info see the State docs

let ref_state = RefMyState::new(cx, MyState {
    field_1: "my_string".into(),
    field_2: 5,
    field_3: MyInnerState {
        field_1: 20,
        collection: vec!["my", "string", "collection"],
    },
    state_collection: Default::default()
});  

Structs

Derive Macros

  • Derive macro for State Management