import React from 'react' // create context with no upfront defaultValue // without having to do undefined check all the time export function createBaseContext() { const ctx = React.createContext(undefined) function useBaseContext() { const ctxConst = React.useContext(ctx) if (!ctxConst) throw new Error('useBaseContext must be inside a Provider with a value') return ctxConst } // make TypeScript infer a tuple, not an array of union types return [ctx, useBaseContext] as const } export interface IBaseAction { type: ActionType & string payload?: any [key: string]: string } export interface IBaseContext { state: S [k: string]: any } export type BaseContextComponent = React.PropsWithChildren