1.0.0 • Published 5 years ago

@customhooks/use-network v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@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>;
}