capacitor-community / react-hooks

⚡️ React hooks for Capacitor ⚡️
Other
246 stars 22 forks source link

Geolocation error is not reset after success #55

Open piotr-cz opened 2 months ago

piotr-cz commented 2 months ago

Describe the bug

The Geolocation error is still being returned from both useCurrentPosition and useWatchPosition hooks, even that the position has been read.

To Reproduce

  1. Disable location permission
  2. Use any of the Geolocation hooks
  3. It returns an object { currentPosition: undefined, error: Error }
  4. Enable location permission
  5. Use any of the Geolocation hooks
  6. It reruns and object { currentPosition: GeolocationPosition, error: Error }

Expected behavior Hooks should not return error when it does not happen

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information): Not tested

Additional context Hooks should reset the error state on success:

 const id = await Geolocation.watchPosition(options || {}, (pos: Position | null, err) => {
-  if (err) {
-    setError(err);
-  }
+  setError(err);
   if (pos) {
     setCurrentPosition(pos);
   }
 });