From b72c09869477b0e3ac666925e4d1cf6d11e29803 Mon Sep 17 00:00:00 2001 From: Wes Souza Date: Mon, 25 Mar 2019 23:39:31 -0400 Subject: [PATCH] fix: types for useGeolocation --- src/useGeolocation.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/useGeolocation.ts b/src/useGeolocation.ts index 4e5a0432bd..4369e83e32 100644 --- a/src/useGeolocation.ts +++ b/src/useGeolocation.ts @@ -2,19 +2,19 @@ import {useState, useEffect} from 'react'; export interface GeoLocationSensorState { loading: boolean, - accuracy: number, - altitude: number, - altitudeAccuracy: number, - heading: number, - latitude: number, - longitude: number, - speed: number, - timestamp: number, + accuracy: number | null, + altitude: number | null, + altitudeAccuracy: number | null, + heading: number | null, + latitude: number | null, + longitude: number | null, + speed: number | null, + timestamp: number | null, error?: Error | PositionError } -const useGeolocation = () => { - const [state, setState] = useState({ +const useGeolocation = (): GeoLocationSensorState => { + const [state, setState] = useState({ loading: true, accuracy: null, altitude: null, @@ -43,7 +43,7 @@ const useGeolocation = () => { }); } }; - const onEventError = (error: any) => + const onEventError = (error: PositionError) => mounted && setState(oldState => ({...oldState, loading: false, error})); useEffect(() => {