This commit is contained in:
Christopher Talib 2019-07-25 16:47:14 +02:00
parent 20d4f30994
commit f9b6dba4d2
2 changed files with 12547 additions and 3 deletions

12533
react/4/seasons/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -6,18 +6,29 @@ class App extends React.Component {
// specific to JS not to React
constructor(props) {
super(props)
this.state = { lat: null }
this.state = { lat: null, errorMessage: '' }
window.navigator.geolocation.getCurrentPosition(
postion => {
this.setState({ lat: postion.coords.latitude })
},
err => console.log(err)
err => {
this.setState({ errorMessage: err.message })
}
)
}
render() {
return <div>Latitude: {this.state.lat}</div>
if (this.state.errorMessage && !this.state.lat) {
return <div>Error: {this.state.errorMessage}</div>
}
if (!this.state.errorMessage && this.state.lat) {
return <div>Latiture: {this.state.lat}</div>
}
return <div>Loading...</div>
}
}
ReactDOM.render(