import React, { Component } from 'react'; import { Observable, Unsubscribable } from 'rxjs'; interface Props { watch: Observable; child: React.ComponentType; initialSubProps: T; } interface State { subProps: T; } export class ObservablePropsWrapper extends Component, State> { sub?: Unsubscribable; constructor(props: Props) { super(props); this.state = { subProps: props.initialSubProps, }; } componentDidMount() { this.sub = this.props.watch.subscribe({ next: (subProps: T) => { //console.log('ObservablePropsWrapper:NEXT', subProps); this.setState({ subProps }); }, complete: () => { //console.log('ObservablePropsWrapper:complete'); }, error: (err) => { //console.log('ObservablePropsWrapper:error', err); }, }); } componentWillUnmount() { if (this.sub) { this.sub.unsubscribe(); } } render() { const { subProps } = this.state; return ; } }