Answers for "React_network-status*onlinestatus.js*"

0

React_network-status*onlinestatus.js*

import {useEffect, useState} from "react";

export default () => {
    const [online, networkStatus] = useState(navigator.onLine);

    useEffect(() => {
        if (window.addEventListener) {
            window.addEventListener("online", () => networkStatus(true), false);
            window.addEventListener("offline", () => networkStatus(false), false);
        } else {
            document.body.ononline = () => networkStatus(true);
            document.body.onoffline = () => networkStatus(false);
        }
    }, []);

    return online;
}
Posted by: Guest on October-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language