Creates a new store with an initial state.
createStore(initialState: TState): Store<TState>initialState: The initial state for the store.
- A store object that contains the state and methods to update it.
A hook to read state values in React components.
useStore<TState, TSelected>(store: Store<TState>, selector: (state: TState) => TSelected): TSelectedstore: The store you want to read from.selector: A function to select a specific part of the state.
A hook to subscribe to store updates and trigger side effects.
useStoreEffect<TState, TSelected>(store: Store<TState>, selector: (state: TState) => TSelected, effect: (state: TState, prevState: TState) => void): voidstore: The store you want to subscribe to.selector: A function to select a specific part of the state.effect: A function that runs when the state changes.
The Store object contains methods for managing state.
update(updater: (state: TState) => TState): Update the state with a new value.effect(selector: (state: TState) => TSelected, effect: (state: TState, prevState: TState) => void): Subscribe to changes in state.