capacitor-community / capacitor-community/react-hooks

Geolocation error is not reset after success

Open
#55 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
267
Forks
24
PR merge metrics
No merged PRs in 30d

Description

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

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.