Created
February 16, 2018 18:14
-
-
Save jtomchak/2acb72b6c83d67c4bb43ec0ef9feee2f to your computer and use it in GitHub Desktop.
GeoAddress for GeoPosition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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