package
Declarative geolocation in React
npm install react-geolocationGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Estimated unpacked size across 1 packages.
27.3 kB
Includes dependencies.
🌎🛰 Declarative geolocation in React
npm install -S react-geolocation<Geolocation
render={({
fetchingPosition,
position: { coords: { latitude, longitude } = {} } = {},
error,
getCurrentPosition
}) =>
<div>
<button onClick={getCurrentPosition}>Get Position</button>
{error &&
<div>
{error.message}
</div>}
<pre>
latitude: {latitude}
longitude: {longitude}
</pre>
booleannumbernumberfunctionrender is a function that receives an object as its only argument.
The object contains the following keys:
booleanIf true then the component will not perform the fetch on mount.
You must use the getCurrentPosition named argument in order to initiate the request.
<Geolocation
lazy
render={({getCurrentPosition, fetchingPosition}) => (
<div>
<button onClick={getCurrentPosition}>Get Current Position</button>
<div>Fetching Position: {fetchingPosition}</div>
</div>
)}
/>
// renders "Fetching Position: false" until the button is clickedfunctioncallback called on success. Its only argument is position
functioncallback called on error. Its only argument is error