1.1.4 • Published 6 years ago

@hypersprite/react-geolocation-hoc v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

React Geolocation HOC

This is a small HOC that injects browser geolocation into the child component.

Usage

Install

npm install @hypersprite/react-geolocation-hoc --save

Import

import ExtGeolocation from '@hypersprite/react-geolocation-hoc';

In Practice

my-map.js user created file imports ExtGeolocation

const MyMap = (props) => {
  const { lat, lng, geolocation, timestamp } = props;
  /** ... all your other component code
  *
  * use the props as you see fit
  *
  */
};

export default ExtGeolocation(MyMap);

Then from your view file

Uses default lat/lng and asks for permission and allows for browser geolocation

<MyMap />

Assigns props as default lat/lng and asks for permission and allows for browser geolocation

<MyMap
  lat={39.28756}
  lng={-120.19987}
/>

Assigns props as default lat/lng and does NOT ask for premission, disables browser geolocation

<MyMap
  lat={39.28756}
  lng={-120.19987}
  noGeolocation
/>

Scripts

use npm run <script>

  • lint - runs linter
  • test - runs test
  • test:dev - runs test in watch mode
  • build - runs build
  • build:dev - runs build in watch mode

npm version <major | minor | patch>

API

Receives Props

prop nametypevaluesdescription
latNumberLatitudesOptional if default needed
lngNumberLongitudeOptional if default needed
noGeolocationBooleantrue or false*true === geolocation is disabled, will not ask

noGeolocation can be used with a pre-dialog box asking if they want to enable geolocaton, this way they can say no to you and not set disabled in the browser, giving you the opportunity to ask the next time. See this Google recommendation for more information.

New Passed Props

prop nametypevaluesdescription
latNumberLatitudesCan pass default props or user location
lngNumberLongitudeCan pass default props or user location
geolocationBooleantrue or false*true: geolocation allowed, false, geolocation blocked
timestampNumberUnix time in seconds
refreshLocationfunction
1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago