import React from 'react' ; import { connect } from 'react-redux' ; import { Subtract } from 'utility-types' ; import { AppState } from '../redux/appState' ; import { ContextState } from '../redux/context/state' ; import { getContext } from '../redux/context/selectors' ; export interface WithContextProps extends ContextState { } const mapStateToProps = ( state ) => ( { ... getContext ( state ) } ) ; const withContext = < P extends WithContextProps > ( WrappedComponent ) => { class WithContext extends React . Component < WithContextProps > { static displayName = `withContext(${ WrappedComponent . name })` ; static readonly WrappedComponent = WrappedComponent ; render ( ) { return < WrappedComponent { ... this . props } / > ; } } return ( connect ( mapStateToProps ) ( WithContext ) as any ) as React . ComponentClass < Subtract < P , WithContextProps > > ; } ; export default withContext ;