Skip to content

Instantly share code, notes, and snippets.

@jtomchak
Created February 16, 2018 18:14
Show Gist options
  • Save jtomchak/2acb72b6c83d67c4bb43ec0ef9feee2f to your computer and use it in GitHub Desktop.
Save jtomchak/2acb72b6c83d67c4bb43ec0ef9feee2f to your computer and use it in GitHub Desktop.
GeoAddress for GeoPosition
import React, { Component } from "react";
import getAddressFromCoords from "./utils/getAddressFromCoords";
class GeoAddress extends Component {
state = { address: null };
componentDidMount() {
//if what?
if (this.props.latitude && this.props.longitude) {
this.getAddress();
}
}
componentDidUpdate(prevProps) {
if (
prevProps.longitude !== this.props.longitude ||
prevProps.latitude !== this.props.latitude
) {
this.getAddress();
}
}
getAddress = () => {
//go get the address using last and long
getAddressFromCoords(this.props.latitude, this.props.longitude)
.then(results =>
this.setState({
address: results
})
)
.catch(err => err);
};
render() {
return this.props.children(this.state);
}
}
export default GeoAddress;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment