0

I would like to check my Internet connection in my Ionic React application. All what I find on Internet is for Ionic angular. How can I do that ?

2 Answers2

2

If you are using Ionic with Capacitor u can use the @capacitor/network api.

Abdes
  • 926
  • 1
  • 15
  • 27
0

Ok thanks, I find something else ...

['load', 'online', 'offline'].forEach(function (e) {
    window.addEventListener(e, () => { props.setNetworkState(navigator.onLine ? "online" : "offline") });
  });
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 06 '21 at 06:41
  • Are you tested it in a real device? window.navigator.onLine works only on the browser but if you target a real device (Android...) it doesn't work. – Abdes Oct 08 '21 at 11:47