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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-network-connectivity

v1.0.3

Published

Advanced React network connectivity status package with hooks, provider, and visual indicators

Readme

react-network-connectivity

Features

  • Accurate connectivity detection by active HTTP ping with fallback to browser status - Latency measurement with real-time updates and automatic timeout handling - Exponential backoff retries to reduce network load on unstable connections - Predictive network status including an "unstable" state for slow/high-latency connections - Easy React integration via Context provider and simple hook for status consumption - Customizable visual indicators with multiple styles and icon sets (including Lucide icons) - Callbacks for reacting to status changes, online/offline transitions
    --- A powerful and flexible React package for detecting and displaying network connectivity status. It combines active ping monitoring with timeout, exponential backoff retries, latency tracking, and predictive statuses (online, offline, unstable, checking). This package provides a React Context provider (<NetworkProvider>) and a convenient hook (useNetworkStatus) for easy access to real-time network state anywhere in your app. Additionally, it offers a customizable Wi-Fi signal indicator component (<WifiSignalIndicator>) with multiple visual styles to suit different UI needs. ---

Installation

Install the package and its peer dependency for icons:

npm install react-network-connectivity lucide-react
# or
yarn add react-network-connectivity lucide-react

--- ## Usage

Wrap your app with the Provider

The NetworkProvider manages active network checks by pinging a specified URL (or falling back to browser status) at configurable intervals, with built-in retry and backoff logic:

import {NetworkProvider} from 'react-network-connectivity';

// Default pingUrl = https://www.google.com/generate_204

<NetworkProvider pingUrl="https://your-api/ping" pingIntervalMs={15000}>
    <YourApp/>
</NetworkProvider>

Consume network status via Hook

Anywhere inside your app, use the useNetworkStatus hook to get up-to-date status, latency, and connection info:

import {useNetworkStatus} from 'react-network-connectivity';

function StatusDisplay() {
    const {isOnline, status, latency, retryPing} = useNetworkStatus();
    return (
        <div>
            <p>Status: {status} (Latency: {latency ? `${latency.toFixed(0)} ms` : 'N/A'})</p>
            {!isOnline && <button onClick={retryPing}>Retry Now</button>}
        </div>
    );
}

Visualize connectivity with Wi-Fi indicator

Use the <WifiSignalIndicator /> component to render network quality visually, with multiple styles:

import {WifiSignalIndicator} from 'react-network-connectivity';

<WifiSignalIndicator variant="lucide" showLabel size={30}/>

Supported variants: 'bars', 'icon', 'text', 'emoji', 'lucide'.

API

<NetworkProvider /> Props

| Prop | Type | Default | Description | |------------------|----------------------------------------|-------------|--------------------------------------------------------------------------| | pingUrl | string | undefined | URL to ping to check connectivity; fallback to browser status if omitted | | pingIntervalMs | number | 15000 | Interval between ping attempts (ms) | | timeoutMs | number | 3000 | Timeout for each ping request (ms) | | backoff | boolean | true | Enables exponential backoff on failures | | maxBackoffMs | number | 60000 | Maximum delay for backoff (ms) | | onStatusChange | (status: ConnectivityStatus) => void | undefined | Callback when status changes | | onOnline | () => void | undefined | Callback when going online | | onOffline | () => void | undefined | Callback when going offline |

useNetworkStatus() Returns

{
    isOnline: boolean; // true if status is 'online' or 'unstable'
    status: 'online' | 'offline' | 'unstable' | 'checking'; // network connectivity status
    latency: number | null; // ping latency in milliseconds or null if unknown
    lastChecked: Date | null; // timestamp of last ping attempt
    lastSuccessAt: Date | null; // timestamp of last successful ping
    error ? : string; // optional error message if ping failed
    retryPing: () => void; // manually trigger a ping attempt
}

🎛️ WifiSignalIndicator Component

A signal strength display component with 5 variant styles.

Props

| Prop | Type | Default | Description | |-------------------|-----------|----------|----------------------------------| | variant | 'bars' | 'icon' | 'emoji' | 'text' | 'lucide' | "bars" | Visual display type | | size | number | 20 | Icon size (for Lucide only) | | showLabel | boolean | false | Display connectivity status text | | showLatency | boolean | false | Display latency in milliseconds | | latencyPosition | 'top' | 'bottom' | 'left' | 'right' | "bottom" | Where to place latency text |

Examples

<WifiSignalIndicator variant="emoji" showLabel showLatency/>
<WifiSignalIndicator variant="lucide" showLabel showLatency size={28}/>
<WifiSignalIndicator variant="text"/>

License

MIT © Jingx

Feel free to contribute or report issues on GitHub.