UNPKG

1.32 kBTypeScriptView Raw
1import React from "react";
2import { ProviderProps } from ".";
3import { Action, Reducer } from "./types";
4export interface Store<S> {
5 useState(): S;
6 useDispatch(): (action: Action<S>, callback?: () => void) => void;
7 persist(state: S, action: {
8 type: any;
9 }): void;
10 setToState(): Promise<void>;
11 dispatch: (action: any, callback?: () => void) => void;
12 state: S;
13 Provider: (props: Omit<ProviderProps<any>, "store">) => any;
14}
15export interface PrivateStore<S> extends Store<S> {
16 stateContext: React.Context<S>;
17 dispatchContext: React.Context<(action: any, callback?: () => void) => void>;
18 reducer: Reducer<S>;
19 initialState: S;
20 persistKey?: string;
21}
22/**
23 * This function gives you a store. Use it in your components where you want to
24 * connect to store and provider
25 */
26export declare const createStore: <T extends {
27 [x: string]: any;
28}>({ reducer, initialState, mapStateToPersist, storage, persistKey, }: {
29 reducer: Reducer<T, {
30 type: any;
31 payload: T;
32 }>;
33 initialState: T;
34 /** Window.localStorage, window.sessionStorage, AsyncStorage supported */
35 storage?: any;
36 persistKey?: string | undefined;
37 mapStateToPersist?: ((state: T) => Partial<T>) | undefined;
38}) => Store<T>;
39//# sourceMappingURL=createStore.d.ts.map
\No newline at end of file