Skip to content

Instantly share code, notes, and snippets.

@jamesattard
Created July 18, 2018 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesattard/a9a9437fabccf4b0f49737601a2e3c5d to your computer and use it in GitHub Desktop.
Save jamesattard/a9a9437fabccf4b0f49737601a2e3c5d to your computer and use it in GitHub Desktop.
Asynchronous setState()
setCoords = coords => {
this.setState({
lat: coords.lat,
lng: coords.lng
});
};
componentDidMount() {
let geocoder = new window.google.maps.Geocoder();
geocoder.geocode(
{ address: this.props.address },
async (results, status) => {
if (status === "OK") {
const coords = await results[0].geometry.location.toJSON();
await this.setCoords(coords);
} else {
console.log(
"Geocode was not successful for the following reason: " + status
);
}
}
);
this.delayedShowMarker();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment