@sampettersson/constate
Version:
Yet another React state management library that lets you work with local state and scale up to global state with ease
49 lines (48 loc) • 1.49 kB
TypeScript
import * as React from "react";
import { StateUpdater, StateCallback, MountContainer, SetContextState } from "./types";
interface OnMountProps<S> {
state: S;
setContextState: SetContextState<S, string>;
}
interface OnUpdateProps<S> {
prevState: S;
state: S;
setContextState: SetContextState<S, string>;
context: string;
type?: string;
}
interface OnUnmountProps<S> {
state: S;
}
export interface ProviderProps<S> {
initialState: Partial<S>;
devtools?: boolean;
onMount?: (props: OnMountProps<S>) => void;
onUpdate?: (props: OnUpdateProps<S>) => void;
onUnmount?: (props: OnUnmountProps<S>) => void;
}
interface ProviderState<S> {
state: S;
setContextState: SetContextState<S, string>;
mountContainer: MountContainer;
}
declare class Provider<State extends {
[key: string]: any;
}> extends React.Component<ProviderProps<State>, ProviderState<State>> {
static defaultProps: {
initialState: {};
};
private containers;
private devtools?;
constructor(props: ProviderProps<State>);
componentDidMount(): void;
componentWillUnmount(): void;
mountContainer: MountContainer;
setContextState: SetContextState<State, string>;
getProps: (type?: string | undefined) => {
state: State;
setContextState: (context: string, updater: Partial<State> | StateUpdater<State>, callback?: StateCallback | undefined) => void;
};
render(): JSX.Element;
}
export default Provider;