1.3.3 • Published 8 months ago

react-nsn v1.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

React Network Status Notification (React-nsn) License npm

ComponentExample
  1. Network status hook useOnlineStatus()
    • app online network status
    • status time info
    • network information
    • custom polling
  2. Notification component <OnlineStatusNotification/>

Table of Contents

Online demo

https://amrahmeda.github.io/react-nsn

Getting Started

npm

npm i react-nsn

How to use

add <OnlineStatusNotification/> to your app, preferably at root level.

import { OnlineStatusNotification, useOnlineStatus } from 'react-nsn'

function App() {
  const {
    attributes,
    isOnline,
    time: { difference, since },
    connectionInfo,
  } = useOnlineStatus()

  // logs current connection info
  console.log(connectionInfo)

  const statusText = isOnline ? `online` : `offline`

  return (
    <div>
      <h1>{`App is ${statusText}`}</h1>
      <h1>{`the app is ${statusText} since: ${since}`}</h1>
      <h1>{`difference in time since the component was ${statusText}: ${difference}`}</h1>
      <OnlineStatusNotification darkMode={true} {...attributes} />
    </div>
  )
}

Documentation

<OnlineStatusNotification/> has the following props:

NameTypeDefaultDescription
darkModebooleanfalsetoggle dark mode
destroyOnClosebooleantruedestroy when notification component unmount
durationnumber4500msduration of the notification when it pops up on screen before hiding back
onRefreshClickfunctionderived from eventsCallback, callback function triggered when refresh is clicked during offline status
onCloseClickfunctionderived from eventsCallback, callback function triggered when close button is clicked
positionstringbottomLeftbottomLeft bottomRight centered
statusText.onlinestringYour internet connection was restored.add your custom online text
statusText.offlinestringYou are currently offline.add your custom offline text

useOnlineStatus hook has the following arguments:

NameTypeDefaultDescription
pollingUrlstringhttps://www.gstatic.com/generate_204the url used to perform polling
pollingDurationnumber12000msfixed delays time between requests

useOnlineStatus hook offers the following:

NameTypeDefaultDescription
isOnlinebooleanapp online status
isOfflinebooleanapp offline status
time.sinceDatespecifies the date of the last status
time.differencestringthe difference in time between latest network status and the current time
connectionInfoThe Network Information API provides information about the system's connection in terms of general connection type (e.g., 'wifi, 'cellular', etc.).
attributesobjectpassed to <OnlineStatusNotification/> as prop

Compatibility

IE / EdgeFirefoxChromeSafariElectron
IE11, Edgelatest versionlatest versionlatest versionlatest version

License

React-nsn is released under the MIT license.

1.2.0

10 months ago

1.3.3

8 months ago

1.2.4

10 months ago

1.3.2

8 months ago

1.2.3

10 months ago

1.3.1

8 months ago

1.0.4

11 months ago

1.3.0

8 months ago

1.2.1

10 months ago

1.0.3

11 months ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.2.0

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago