react-adaptive-hooks icon indicating copy to clipboard operation
react-adaptive-hooks copied to clipboard

Offline Detection?

Open rrLucho opened this issue 6 years ago • 4 comments

is there a way to detect offline state in the network, so we can serve different content, using the hooks?

rrLucho avatar Nov 25 '19 17:11 rrLucho

I think this would be a great addition to the useNetworkStatus hook. I think the online/offline events API could be used.

mlampedx avatar Nov 27 '19 01:11 mlampedx

Hi :)

I created a pull request for this feature -> #45

JCofman avatar Jan 08 '20 22:01 JCofman

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.

anton-karlovskiy avatar Mar 10 '20 16:03 anton-karlovskiy

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

JCofman avatar Mar 17 '20 14:03 JCofman