1.0.0 • Published 4 years ago

@ej-hooks/use-network v1.0.0

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

@ej-hooks/use-network

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

Installation

yarn

yarn add @ej-hooks/use-network

npm

npm i @ej-hooks/use-network

Usage

import React from 'react';
import useNetwork from '@ej-hooks/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