Skip to content

Geolocation error is not reset after success #55

@piotr-cz

Description

@piotr-cz

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):

  • OS: Windows
  • Browser Chrome
  • Version 126.0.6478.127

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);
   }
 });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions