-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
42 lines (38 loc) · 1.57 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
declare module 'react-context-simply' {
import {
FunctionComponent,
Context,
Dispatch
} from 'react';
export interface IActions
{
[action: string] : Function;
}
export interface IAction {
type: string;
payload?: any;
}
export type StateMiddleware = <T>(stateContext: ContextState<T>) => ContextState<T> | void
export interface IMiddleware {
action: string;
middleware: StateMiddleware;
}
export type ContextState<T> = [T, Dispatch<IAction>];
export type Reducer<T> = (state: T, action: IAction) => T;
export interface IStateContext<T> {
useStateValue(): ContextState<T>;
StateProvider: FunctionComponent;
StateContext: Context<ContextState<T>>;
}
/**
* creates the provider as well as the hook that returns store and actions
*
* @param {T} initialState The initial State to begin with
* @param {Reducer<T>} reducer it describes how an action transforms the state into the next state
* @param {IActions} actions sets of actions that holds information that send data to your store
* @param {IMiddleware | IMiddleware[]} middleware array of objects, each contain the middleware function and action that will be hooked to it
* @returns {IStateContext<T>} it return basically our provider also a hook function that will return our store and actions
* @public
*/
export default function createStateContext(initialState: T, reducer: Reducer<T>, actions: IActions, middleware?: IMiddleware | IMiddleware[]): IStateContext<T>
}