Reputation:
I know that SetState takes a callback, which I´m using. For some reason, though, it is not running after the state updates. Am I doing something wrong?
handleInputChange = (event) => {
this.setState({
[name]: event.target.value
});
if(event.target.value.length > 1) {
this.getSuggestions();
this.setState({
query: event.target.value,
}, () => this.getCoordinates)
}
getCoordinates = () =>{
const geocoder = new google.maps.Geocoder();
geocoder.geocode( {"address":this.state.query}, this.onSuccessGetAddress)
}
Upvotes: 1
Views: 48
Reputation: 1127
You provided a callback which returns the function this.getCoordinates
:
() => this.getCoordinates
You want to provide a callback which calls this.getCoordinates
:
() => this.getCoordinates()
or
this.getCoordinates
Upvotes: 5