contextism
Version:
New way to use React Context
15 lines (14 loc) • 1.04 kB
TypeScript
import * as React from 'react';
declare const createStore: <S, A = {}>(defaultState?: S | undefined) => {
stateContext: React.Context<S | undefined>;
dispatchContext: React.Context<React.Dispatch<React.SetStateAction<S>> | React.Dispatch<A> | undefined>;
useStateContext: () => S;
useDispatchContext: () => React.Dispatch<React.SetStateAction<S>> | React.Dispatch<A>;
useStore: () => [S, React.Dispatch<React.SetStateAction<S>> | React.Dispatch<A>];
Provider: ({ state, dispatch, children }: {
state: S;
dispatch?: React.Dispatch<React.SetStateAction<S>> | React.Dispatch<A> | undefined;
children?: string | number | boolean | {} | React.ReactChildren | React.ReactElement<any, string | ((props: any) => React.ReactElement<any, string | any | (new (props: any) => React.Component<any, any, any>)> | null) | (new (props: any) => React.Component<any, any, any>)> | React.ReactNodeArray | React.ReactPortal | null | undefined;
}) => JSX.Element;
};
export default createStore;