UNPKG

react-principal

Version:

A state management with react context for apps which using hooks.

39 lines 1.32 kB
import React from "react"; import { ProviderProps } from "."; import { Action, Reducer } from "./types"; export interface Store<S> { useState(): S; useDispatch(): (action: Action<S>, callback?: () => void) => void; persist(state: S, action: { type: any; }): void; setToState(): Promise<void>; dispatch: (action: any, callback?: () => void) => void; state: S; Provider: (props: Omit<ProviderProps<any>, "store">) => any; } export interface PrivateStore<S> extends Store<S> { stateContext: React.Context<S>; dispatchContext: React.Context<(action: any, callback?: () => void) => void>; reducer: Reducer<S>; initialState: S; persistKey?: string; } /** * This function gives you a store. Use it in your components where you want to * connect to store and provider */ export declare const createStore: <T extends { [x: string]: any; }>({ reducer, initialState, mapStateToPersist, storage, persistKey, }: { reducer: Reducer<T, { type: any; payload: T; }>; initialState: T; /** Window.localStorage, window.sessionStorage, AsyncStorage supported */ storage?: any; persistKey?: string | undefined; mapStateToPersist?: ((state: T) => Partial<T>) | undefined; }) => Store<T>; //# sourceMappingURL=createStore.d.ts.map