Can someone help me relate the state of React to the RxJS Observable? I liked it
componentDidMount() {
let source = Rx.Observable.of(this.state.val)
}
The ideal result is when updating this.state.val(through this.setState(...)) source, so I can combine sourcewith another RxJS observable stream.
However, in this case, it is sourceupdated only once, even after it is this.state.valupdated, and the component is re-displayed.
this.state.val = 1
source.subscribe(val => console.log(x))
this.state.val = 2
source.subscribe(val => console.log(val))
this.state.val = 1
source.subscribe(val => console.log(x))
this.state.val = 2
source.subscribe(val => console.log(val))
Perhaps this is because it componentDidMount()is called only once during the Response. so I move sourceto componentDidUpdate(), which is called every time after rendering the component. However, the result still remains the same.
So, the question is, how do I update sourcewhen updating this.state.val?
: , , Rx.Subject
constructor() {
super(props)
this.source = new Rx.Subject()
_onChangeHandler(e) {
this.source.onNext(e.target.value)
}
componentDidMount() {
this.source.subscribe(x => console.log(x))
}
render() {
<input type='text' onChange={this._onChangeHandler} />
}