Open rrLucho opened 4 years ago
I think this would be a great addition to the useNetworkStatus hook. I think the online/offline events API could be used.
Hi :)
I created a pull request for this feature -> #45
We shouldn't land support for navigator.onLine API because the API itself is unreliable.
https://natalian.org/2012/07/16/navigator.onLine/ https://blog.superhuman.com/building-reliable-apps-on-unreliable-networks-3f75743fc457
The way browsers implement navigator.onLine means that you would likely need to do something much more custom to get what you are actually after.
Per MDN, in Chrome and Safari, if the browser is not able to connect to a local area network (LAN) or a router, it is offline; all other conditions return true. So while you can assume that the browser is offline when it returns a false value, you cannot assume that a true value necessarily means that the browser can access the internet.
As mentioned by @anton-karlovskiy the method used for the pull request is fragile but if you still want to use offline detection using the navigator.onLine API
you can checkout -> https://github.com/jaredpalmer/the-platform#usenetworkstatus
I think we can close this issue? :)
is there a way to detect offline state in the network, so we can serve different content, using the hooks?