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-network-status-indicator

v1.0.1

Published

Network status hook and indicator for react apps

Readme

React Network Status Indicator

A lightweight React library to monitor and display network status with customizable notifications. Includes a notifier component and a React hook for monitoring online/offline status and connection type.

npm MIT npm downloads


Table of Contents


Features

  • Detects online/offline status dynamically.
  • Provides a customizable notifier for network status changes.
  • Exposes a React hook to monitor network connectivity and connection type.
  • Lightweight and fully written in TypeScript.
  • Easy integration into any React application.
  • Fully customizable:
    • Custom text for online/offline messages.
    • Configurable message durations.
    • Adjustable positioning of the notifier.

Installation

Install the library using npm:

npm install react-network-status-indicator

Or using Yarn:

yarn add react-network-status-indicator

Usage

Basic Example

Here’s a simple example showing how to use the NetworkStatusNotifier component and the useNetworkStatus hook:

import React from 'react';
import { NetworkStatusNotifier, useNetworkStatus } from 'react-network-status-indicator';

function App() {
  const { isOnline, connectionType } = useNetworkStatus();

  return (
    <div>
      <NetworkStatusNotifier />
      <p>Is Online: {isOnline ? 'Yes' : 'No'}</p>
      <p>Connection Type: {connectionType}</p>
    </div>
  );
}

export default App;

NetworkStatusNotifier Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | onlineText | string | "You are back online!" | Text displayed when the network is online. | | offlineText | string | "You are offline." | Text displayed when the network is offline. | | onlineTextShowDuration | number | 3000 | Duration (ms) to display the online message. | | offlineTextShowDuration | number | 3000 | Duration (ms) to display the offline message. | | position | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "top-right" | Position of the notifier. | | className | string | "" | Additional CSS class for custom styles. | | style | object | {} | Inline styles for the notifier container. |

Customizing the Component

You can customize the NetworkStatusNotifier component by changing its messages, position, duration, and styles.

Example with Customization

import React from 'react';
import { NetworkStatusNotifier } from 'react-network-status-indicator';

function App() {
  return (
    <div>
      <NetworkStatusNotifier
        onlineText="Yay! Network is back online 🎉"
        offlineText="Oops! You're offline 😟"
        onlineTextShowDuration={5000}
        offlineTextShowDuration={4000}
        position="bottom-left"
        style={{
          color: "white",
          backgroundColor: "blue",
          borderRadius: "8px",
        }}
        className="custom-network-notifier"
      />
    </div>
  );
}

export default App;

Using the useNetworkStatus Hook

The useNetworkStatus hook provides the current network status and connection type.

Hook Signature

function useNetworkStatus(): {
  isOnline: boolean | null;
  connectionType: string;
  hasNetworkChanged: boolean;
}
Example Usage
tsx
Copy code
import React from 'react';
import { useNetworkStatus } from 'react-network-status-indicator';

function NetworkInfo() {
  const { isOnline, connectionType } = useNetworkStatus();

  return (
    <div>
      <p>Is Online: {isOnline ? 'Yes' : 'No'}</p>
      <p>Connection Type: {connectionType}</p>
    </div>
  );
}

export default NetworkInfo;

Custom Styles

Add custom styles via the style prop or CSS classes.

Example with CSS
styles.css:

css
Copy code
.custom-network-notifier {
  font-size: 16px;
  padding: 10px;
  border: 2px solid white;
}

Component Usage:

<NetworkStatusNotifier className="custom-network-notifier" />

Contributing Contributions are welcome! If you find a bug or want to suggest a feature, please open an issue or submit a pull request.

License This project is licensed under the MIT License.