@customhooks/use-network
v1.0.0
Published
React Hook to listen when the user goes online or offline
Downloads
2
Maintainers
Readme
@customhooks/use-network
React Hook to listen when the user goes online or offline.
Installaction
npm install @customhooks/use-network
or
yarn add @customhooks/use-network
Usage
useNetwork()
have a one argument like this :useNetwork(onChange)
onChange
is must be function.
import React from "react";
import useNetwork from "@nooks/use-network";
function App() {
const onNetworkChange = (isOnline) => {
console.log(isOnline ? "Online Now" : "Offline Now");
};
const isOnline = useNetwork(onChange);
return <h1>{isOnline ? "Online" : "Offline"}</h1>;
}