UNPKG

core-resource-app-test

Version:

App that contains assets and scripts for the core apps

29 lines (23 loc) 802 B
import React, { Component } from 'react'; import log from 'loglevel'; export default function withStateFrom(stateSource$, BaseComponent) { const withStateForm = class extends Component { componentDidMount() { this.disposable = stateSource$ .subscribe( (state) => this.setState(state), (error) => log.error(error) ); } componentWillUnmount() { this.disposable && this.disposable.dispose && this.disposable.dispose(); } render() { return ( <BaseComponent {...this.state} {...this.props} /> ); } }; withStateForm.displayName = BaseComponent.displayName || BaseComponent.name; return withStateForm; }