📌React Hook to listen when the user goes online or offline.
Installation
npm
npm i @bro95-hooks/use-network
Usage
importReactfrom"react";importuseNetworkfrom"@bro95-hooks/use-network";functionApp(){constonNetworkChange=isOnline=>console.log(isOnline ? "We are back online" : "We just got offline");constisOnline=useNetwork(onNetworkChange);return<h1>{isOnline ? "We are online" : "We are offline"}</h1>;}
Arguments
Argument
Type
Description
Arguments
Required
onNetworkChange
function
Function to be called when the network status changes
isOnline : Boolean
no
Return
Return value
Type
Description
Default value
isOnline
Boolean
A boolean representing if the user is online or not