import { useContext, createContext } from 'react'; export interface Store { Provider: (props: ProviderProps) => any useStore: () => T } interface ProviderProps{ children?: any } export type Hook = (params?: P) => S export function createStore(useHook: Hook, params?: P): Store { const Context = createContext(null); const Provider = (props: ProviderProps) => { return {props.children}; }; function useStore(): ObservableState { const state = useContext(Context); if (state === null) { // throw new Error("your target Component must be wrapped by Provider"); return {} as any } return state; } return { Provider, useStore }; }