Skip to content

Instantly share code, notes, and snippets.

@robwelan
Created October 12, 2019 22:29
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 robwelan/6557579d88bd340ddc342fcb411c6a92 to your computer and use it in GitHub Desktop.
Save robwelan/6557579d88bd340ddc342fcb411c6a92 to your computer and use it in GitHub Desktop.
import React from 'react';
import { getMyLocation } from '../utilities';
const withLocation = (WrappedComponent) => (
class extends React.Component {
constructor(props) {
super(props);
this.state = {
accuracy: null,
altitude: null,
altitudeAccuracy: null,
error: {},
heading: null,
latitude: null,
longitude: null,
speed: null,
timestamp: null,
withLocation: {
complete: false,
},
};
}
async componentDidMount() {
await getMyLocation()
.then((location) => {
this.setState((prevState) => (
{
...prevState,
...location,
withLocation: {
complete: location.error.code === 0,
},
}
));
});
}
render() {
const {
error,
latitude,
longitude,
withLocation: internalChecks,
} = this.state;
const location = {
error,
latitude,
longitude,
};
return internalChecks.complete ? <WrappedComponent location={location} {...this.props} /> : null;
}
});
export default withLocation;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment