import { Component , createElement } from 'react' ; import { Stapp } from 'stapp' ; import { STAPP_REACT } from '../helpers/constants' ; import { consumerPropTypes } from '../helpers/propTypes' ; import { StappSubscription } from '../helpers/StappSubscription' ; import { ConsumerProps } from '../models/Props' ; import { StappContext } from '../shared/StappContext' ; export class Consumer < State , Api > extends Component < ConsumerProps < State , Api , any > > { static displayName = 'Stapp.Consumer' ; static propTypes : any = consumerPropTypes ; render ( ) { return createElement ( StappContext . Consumer , { children : ( app ) => { if ( ! app ) { throw new Error ( `${ STAPP_REACT } error: Provider missing!` ) ; } return createElement ( StappSubscription , Object . assign ( { app } , this . props as any ) ) ; } } ) ; } }