state = {
locationData: {}
}
componentDidMount() {
axios.get('...')
.then(res => {
const data = res.data;
parseString(data, function (err, result) {
this.setState({locationData: result.data[0]}, function(){console.log(this.state.locationData);})
});
})
}
Gives me the error:
Uncaught (in promise) TypeError: Cannot read property 'setState' of undefined
I've found I need to bind but I don't understand how to in this instance.