streamich / react-use

React Hooks — 👍
http://streamich.github.io/react-use
The Unlicense
41.71k stars 3.14k forks source link

Loading state will never turn to error state when geolocation disabled in system preferences #1849

Open gadzhimari opened 3 years ago

gadzhimari commented 3 years ago

What is the current behaviour? Let's imagine, when user first time load the page and geolocation disabled in system preferences in OS, then loading state always stay in this status and user will never know that it's error.

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your CodeSandbox example below: 2021-02-27_09-41-12

What is the expected behavior? Return error from useGeolocation hook, when geolocation disabled in system preferences

A little about versions:

erikjung commented 3 years ago

It looks like passing a position options argument is a workaround for this, though I would also expect the error to occur immediately if location services are disabled.

function App() {
  const { loading, error } = useGeolocation({ timeout: 5000 })

  if (loading) {
    return 'Loading...'
  }

  if (error) {
    return error.message
  }
}

// should render "Timeout expired" after 5 seconds
gadzhimari commented 3 years ago

You're right, this is the only solution to solve this issue

erikjung commented 3 years ago

Also worth noting, the usePermission hook might be helpful to detect this before invoking the geolocation hook.