Open gadzhimari opened 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
You're right, this is the only solution to solve this issue
Also worth noting, the usePermission hook might be helpful to detect this before invoking the geolocation hook.
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:What is the expected behavior? Return error from useGeolocation hook, when geolocation disabled in system preferences
A little about versions:
react-use
: 17.1.1