Skip to content

Commit

Permalink
feat: support options for useGeolocation
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich authored Apr 23, 2019
2 parents 9e8873e + 01959a1 commit 7d4c59e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions docs/useGeolocation.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# `useGeolocation`

React sensor hook that tracks user's geographic location.

React sensor hook that tracks user's geographic location. This hook accepts [position options](https://developer.mozilla.org/docs/Web/API/PositionOptions).

## Usage

Expand All @@ -18,3 +17,9 @@ const Demo = () => {
);
};
```

## Reference

```ts
useGeolocation(options: PositionOptions)
```
6 changes: 3 additions & 3 deletions src/useGeolocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface GeoLocationSensorState {
error?: Error | PositionError;
}

const useGeolocation = (): GeoLocationSensorState => {
const useGeolocation = (options?: PositionOptions): GeoLocationSensorState => {
const [state, setState] = useState<GeoLocationSensorState>({
loading: true,
accuracy: null,
Expand Down Expand Up @@ -47,8 +47,8 @@ const useGeolocation = (): GeoLocationSensorState => {
mounted && setState(oldState => ({ ...oldState, loading: false, error }));

useEffect(() => {
navigator.geolocation.getCurrentPosition(onEvent, onEventError);
watchId = navigator.geolocation.watchPosition(onEvent, onEventError);
navigator.geolocation.getCurrentPosition(onEvent, onEventError, options);
watchId = navigator.geolocation.watchPosition(onEvent, onEventError, options);

return () => {
mounted = false;
Expand Down

0 comments on commit 7d4c59e

Please sign in to comment.