react-use
Advanced tools
Comparing version 5.3.1 to 5.4.0
@@ -0,1 +1,8 @@ | ||
# [5.4.0](https://github.com/streamich/react-use/compare/v5.3.1...v5.4.0) (2019-02-19) | ||
### Features | ||
* add error and loading fields to useGeolocation ([6909a69](https://github.com/streamich/react-use/commit/6909a69)) | ||
## [5.3.1](https://github.com/streamich/react-use/compare/v5.3.0...v5.3.1) (2019-02-17) | ||
@@ -2,0 +9,0 @@ |
export interface GeoLocationSensorState { | ||
loading: boolean; | ||
accuracy: number; | ||
@@ -10,4 +11,6 @@ altitude: number; | ||
timestamp: number; | ||
error?: Error | PositionError; | ||
} | ||
declare const useGeolocation: () => { | ||
loading: boolean; | ||
accuracy: null; | ||
@@ -14,0 +17,0 @@ altitude: null; |
@@ -6,2 +6,3 @@ "use strict"; | ||
const [state, setState] = react_1.useState({ | ||
loading: true, | ||
accuracy: null, | ||
@@ -21,2 +22,3 @@ altitude: null, | ||
setState({ | ||
loading: false, | ||
accuracy: event.coords.accuracy, | ||
@@ -33,5 +35,6 @@ altitude: event.coords.altitude, | ||
}; | ||
const onEventError = (error) => mounted && setState(oldState => (Object.assign({}, oldState, { loading: false, error }))); | ||
react_1.useEffect(() => { | ||
navigator.geolocation.getCurrentPosition(onEvent); | ||
watchId = navigator.geolocation.watchPosition(onEvent); | ||
navigator.geolocation.getCurrentPosition(onEvent, onEventError); | ||
watchId = navigator.geolocation.watchPosition(onEvent, onEventError); | ||
return () => { | ||
@@ -38,0 +41,0 @@ mounted = false; |
{ | ||
"name": "react-use", | ||
"version": "5.3.1", | ||
"version": "5.4.0", | ||
"description": "Collection of React Hooks", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
88317
1907