how to check internet connection in react js code example
Example 1: react check internet connection
// Trigger sth, when Connection comes back | Connection gets lost
function poopityScoop(){
window.ononline = (event) => {
console.log("Back Online")
};
window.onoffline = (event) => {
console.log("Connection Lost")
};
}
Example 2: react check internet connection
// check the current Connection State
console.log(navigator.onLine)
// true - When internet connection is detected.
// false - When internet connection is not detected.