1.0.1 • Published 5 years ago

@loyhooks/use-network v1.0.1

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

@loyhooks/use-network

React Hook to listen when the user goes online or offline.

Installation

yarn

yarn add @loyhooks/use-network

npm

npm i @loyhooks/use-network

Usage

import React from "react";
import useNetwork from "@loyhooks/use-network";

function App() {
  const onNetworkChange = isOnline =>
    console.log(isOnline ? "We are back online" : "We just got offline");
  const isOnline = useNetwork(onNetworkChange);
  return <h1>{isOnline ? "We are online" : "We are offline"}</h1>;
}

Arguments

ArgumentTypeDescriptionArgumentsRequired
onNetworkChangefunctionFunction to be called when the network status changesisOnline : Booleanno

Return

Return valueTypeDescriptionDefault value
isOnlineBooleanA boolean representing if the user is online or nottrue
1.0.1

5 years ago

1.0.0

5 years ago