UNPKG

@ffsm/store

Version:

A powerful state management library for React, providing a simple and efficient way to manage application state with built-in support for serialization, deserialization, and type safety.

16 lines (15 loc) 990 B
import { PropsWithChildren } from 'react'; import { CreateSliceOptions, PayloadAction, SliceReducers } from './create-slice'; export type Store<State, Reducers extends SliceReducers<State>> = StoreActions<State, Reducers> & { state: State; }; export type StoreActions<State, Reducers extends SliceReducers<State>> = { [K in keyof Reducers]: Reducers[K] extends (state: State) => void ? () => void : Reducers[K] extends (state: State, action: PayloadAction<infer P>) => void ? (payload: P) => void : Reducers[K] extends (state: State, ...args: infer A) => void ? (...args: A) => void : () => void; }; export type StoreContext<State, Reducers extends SliceReducers<State>> = { state: State; } & StoreActions<State, Reducers>; export declare function createStore<State, Reducers extends SliceReducers<State>>(options: CreateSliceOptions<State, Reducers>): { useStore: () => State & StoreActions<State, Reducers>; Provider: (props: PropsWithChildren<{}>) => JSX.Element; };