@minax/redux-hooks
Version:
Achieve Redux By React Hooks
74 lines (73 loc) • 2.19 kB
TypeScript
import React from 'react';
declare const StoreContext: React.Context<{
state: any;
actions: any;
}>;
declare const getStoreContext: <S, A>() => React.Context<{
state: S;
actions: A;
}>;
interface State {
[key: string]: any;
}
interface Action<T> {
error?: boolean;
type: keyof T;
payload?: any;
}
interface Actions {
[name: string]: (args?: any) => any;
}
/**
* S: interface of store
*
* A: type of actions (`typeof actions`)
*/
export interface createReducer<S, A> {
(state: S, action: Action<A>): S;
}
declare const Provider: (props: {
reducer: (state: any, action: any) => any;
actions: {
[name: string]: (args: any) => any;
};
store: {
[key: string]: any;
};
children: any;
additions?: string[] | undefined;
}) => React.ComponentElement<any, any>;
declare const connect: (Cpt: any) => {
new (props: Readonly<{}>): {
render(): JSX.Element;
context: any;
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
forceUpdate(callBack?: (() => void) | undefined): void;
readonly props: Readonly<{}> & Readonly<{
children?: React.ReactNode;
}>;
state: Readonly<{}>;
refs: {
[key: string]: React.ReactInstance;
};
};
new (props: {}, context?: any): {
render(): JSX.Element;
context: any;
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
forceUpdate(callBack?: (() => void) | undefined): void;
readonly props: Readonly<{}> & Readonly<{
children?: React.ReactNode;
}>;
state: Readonly<{}>;
refs: {
[key: string]: React.ReactInstance;
};
};
contextType?: React.Context<any> | undefined;
};
export interface InjectProps<S = State, A = Actions> {
state: S;
actions: A;
}
export { getStoreContext, connect, Provider, StoreContext };