Language: React/JavaScript ES6
Bundling Tool: Webpack(babel-loader 6.0.0)
Other Libs Involved : Leaflet
Problem:
With the function below the context this
is bound to the
component as I need.
Before:
componentDidMount: function() {
map.on('draw:created', function(e){
this.setState({someProp:propUpdate});
featureGroup.addLayer(e.layer);
}.bind(this));
}
But when I switched it over to using the arrow function I expected
an equivalent binding, but this
changed to a leaflet Class
o.Class.extend.e
- leaving this.setState
undefined.
After:
componentDidMount: function() {
map.on('draw:created', (e) => {
this.setState({someProp:propUpdate});
featureGroup.addLayer(e.layer);
});
}
Question: Why is using the arrow function not the equivalent of
binding this
in my case?