UNPKG

@genshi/react

Version:

A simple, composable and effective JavaScript state management library for React

24 lines (23 loc) 785 B
import * as Genshi from "@genshi/core"; type Store<State> = Genshi.Store<State>; type Accessor<State, Value> = (state: State) => Value; /** * Create a store with an initial state value and an optional name. * This provides a `useStore` hook for consumers to use in their components. * * It also returns the store instance for consumers to use, to create actions and effects. * * ```tsx * const [useStore, store] = createStore<{ * count: number; * }); * * const increment = store.action("increment", ({ state }) => ({ * ...state, * count: state.count + 1, * })); * * ``` */ export declare function createStore<State>(initialState: State, config?: Genshi.StoreConfig): [<Value>(accessor: Accessor<State, Value>) => [Value, Genshi.Dispatch], Store<State>]; export {};