React hook useNetworkStatus() returns whether the client's browser online with updates when the network state is changed.
The easiest way to use useNetworkStatus React hook is to install it from npm or yarn.
npm install use-network-status --saveOr
yarn add use-network-statusPull the hook into your component (usually the root one) and call the hook inside the functional component.
import { useNetworkStatus } from "use-network-status";
function App() {
const isOnline = useNetworkStatus();
return (
<div className="status">
{isOnline ? '📡 Online' : '📴 Offline'}
</div>
);
}