npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-nsn

v2.5.2

Published

Detect online/offline status in React. Hook + notification component. Zero deps, SSR-safe, React 16-19.

Readme

React Network Status Notification (React-nsn)

npm version npm downloads bundle size CI TypeScript zero dependencies License

Component | Example :-------------------------:|:-------------------------: |

  1. Network status hook useOnlineStatus()
    • app online network status
    • status time info
    • network information
    • custom polling with exponential backoff
    • onStatusChange callback
    • checkNow() for manual connectivity checks
    • custom pollingFn for your own health-check logic
  2. Notification component <OnlineStatusNotification/>
  3. Headless mode — use only the hook without the notification UI (~1.4KB gzipped)

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>
  )
}

Headless mode

If you only need the hook without the notification component, import from react-nsn/headless for a smaller bundle (~1.4KB gzipped vs ~10.7KB):

import { useOnlineStatus } from 'react-nsn/headless'

function App() {
  const { isOnline, checkNow } = useOnlineStatus({
    onStatusChange: (online) => console.log('Status changed:', online),
  })

  return <p>{isOnline ? 'Online' : 'Offline'}</p>
}

Documentation

<OnlineStatusNotification/> has the following props:

| Name | Type | Default | Description | |------------ |--------------- |--------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | className | string | | additional CSS class name(s) for the notification container | | darkMode | boolean | false | toggle dark mode | | destroyOnClose | boolean | true | remove notification from DOM when it hides | | duration | number | 4500ms | duration of the notification when it pops up on screen before hiding back | | eventsCallback.onRefreshClick | function | | callback triggered when refresh is clicked during offline status | | eventsCallback.onCloseClick | function | | callback triggered when close button is clicked | | position | string | bottomLeft | topLeft topRight topCenter bottomLeft bottomRight bottomCenter | | statusText.online | string | Your internet connection was restored. | custom online text | | statusText.offline | string | You are currently offline. | custom offline text | | style | CSSProperties | | inline styles for the notification container |

The component exposes an imperative handle via ref with openStatus() and dismiss() methods.

useOnlineStatus hook has the following arguments:

| Name | Type | Default | Description | |------------ |--------------- |--------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | pollingUrl | string | https://www.gstatic.com/generate_204 | url used to perform polling | | pollingDuration | number | 12000ms | base delay between requests (backs off exponentially when offline, capped at 60s) | | pollingFn | () => Promise<boolean> | | custom connectivity check — return true if online, false if offline. Overrides pollingUrl | | onStatusChange | (isOnline: boolean) => void | | callback fired when status changes (skips initial render) |

useOnlineStatus hook offers the following:

| Name | Type | Description | |------------ |--------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | isOnline | boolean | app online status | | isOffline | boolean | app offline status | | checkNow | () => Promise<void> | manually trigger a connectivity check | | time.since | Date | date of the last status change | | time.difference | string | human-readable time since last status change | | connectionInfo | NetworkInformation \| null | Network Information API data (connection type, effective type, etc.) | | attributes | object | pass directly to <OnlineStatusNotification/> as props |

Next.js / Server Components

This library relies on browser APIs (window, navigator) and React client hooks, so it is client-side only. If you are using Next.js App Router, wrap your usage in a client component:

'use client'

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

export default function NetworkStatus() {
  const { attributes } = useOnlineStatus()
  return <OnlineStatusNotification {...attributes} />
}

Compatibility

| IE / Edge | Firefox | Chrome | Safari | Electron | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | IE11, Edge | latest version | latest version | latest version | latest version |

License

React-nsn is released under the MIT license.