From b33802d03adf925cdfb29a1bcaa327e7e0c114b7 Mon Sep 17 00:00:00 2001 From: Denys Dovhan Date: Tue, 23 Apr 2019 17:54:48 +0300 Subject: [PATCH 1/3] Add options for useGeolocation --- src/useGeolocation.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/useGeolocation.ts b/src/useGeolocation.ts index acc476980e..3a4a36b031 100644 --- a/src/useGeolocation.ts +++ b/src/useGeolocation.ts @@ -13,7 +13,7 @@ export interface GeoLocationSensorState { error?: Error | PositionError; } -const useGeolocation = (): GeoLocationSensorState => { +const useGeolocation = (options: PositionOptions): GeoLocationSensorState => { const [state, setState] = useState({ loading: true, accuracy: null, @@ -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; From f7e713330bef5e517622a989653a11403e918072 Mon Sep 17 00:00:00 2001 From: Denys Dovhan Date: Tue, 23 Apr 2019 18:00:52 +0300 Subject: [PATCH 2/3] Update docs for useGeolocation --- docs/useGeolocation.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/useGeolocation.md b/docs/useGeolocation.md index c836471235..91ad346fb7 100644 --- a/docs/useGeolocation.md +++ b/docs/useGeolocation.md @@ -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 @@ -18,3 +17,9 @@ const Demo = () => { ); }; ``` + +## Reference + +```ts +useGeolocation(options: PositionOptions) +``` From 01959a12e391d0e235e0433aa6ad9af9f1fcfd0d Mon Sep 17 00:00:00 2001 From: Va Da Date: Tue, 23 Apr 2019 22:01:20 +0200 Subject: [PATCH 3/3] fix: make options useGeolocation optional --- src/useGeolocation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/useGeolocation.ts b/src/useGeolocation.ts index 3a4a36b031..5df7ac0b6f 100644 --- a/src/useGeolocation.ts +++ b/src/useGeolocation.ts @@ -13,7 +13,7 @@ export interface GeoLocationSensorState { error?: Error | PositionError; } -const useGeolocation = (options: PositionOptions): GeoLocationSensorState => { +const useGeolocation = (options?: PositionOptions): GeoLocationSensorState => { const [state, setState] = useState({ loading: true, accuracy: null,