import * as React from "react"; import { AppState } from "@client/state"; const StateContext = React.createContext(null); export interface ProvideStateProps { state: AppState; children: React.ReactNode; } export function ProvideState({ state, children }: ProvideStateProps) { return ( {children} ); } export interface ConsumeStateProps { children: (state: AppState) => React.ReactNode; } export function ConsumeState({ children }: ConsumeStateProps) { const consumeState = (state: AppState | null) => { if (state == null) { throw new Error("Component with ConsumeState must be mounted inside ProvideState"); } return children(state); }; return {consumeState}; } type Diff = ({[P in T]: P } & {[P in U]: never } & { [x: string]: never })[T]; type Omit = {[P in Diff]: T[P]}; export function injectState

(Component: React.ComponentType

): React.ComponentClass> { return class extends React.Component> { render() { const consumeState = (state: AppState | null) => { if (state == null) { throw new Error("Component with injectState must be mounted inside ProvideState"); } return ; }; return {consumeState}; } }; }