Level 3
I'm no Javascript guru, but I think you can do something like this:
channel.bind('my_event', function(data) {
this.setState({ message: data.message });
}.bind(this));
Getting confused with "this" again!
I got this working using the myThis hack but can't understand why using .bind(this) on the channel doesn't work...can any js guru explain?
// Register pusher listener
componentDidMount: function() {
var pusher = new Pusher('18262.........c037');
var channel = pusher.subscribe('test_channel');
var myThis = this;
channel.bind('my_event', function(data) {
myThis.setState({ message : data.message });
});
},
I'm no Javascript guru, but I think you can do something like this:
channel.bind('my_event', function(data) {
this.setState({ message: data.message });
}.bind(this));
Please or to participate in this conversation.