I am using React Native with RxJS and up until now, whenever I subscribe to an observable I have been doing:
observable.subscribe(() => {
this.setState({ loading: true });
}.bind(this));
But since I upgraded to React Native 0.16.0, everywhere I have performed bind(this) on an inline function declared with the ES2015 arrow notation, React Native picks it up as an error. However when I change the arrow notation back to ES5 regular function notation as below:
observable.subscribe(function() => {
this.setState({ loading: true });
}.bind(this));
The errors seem to go away.
What is going on here?
When you use an arrow function you're already binding this to that particular function. So:
() => {} === function() {}.bind(this)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With