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

@custom-react-hooks/use-network

v1.0.1

Published

A React hook for monitoring network status and connection information

Readme

useNetwork Hook

The useNetwork hook is designed for monitoring network status and connection information in React applications. It provides real-time information about the user's network connection including online/offline status, connection speed, and connection type.

Features

  • Network Status Monitoring: Tracks online/offline status in real-time.
  • Connection Information: Provides detailed network connection data when available.
  • Automatic Updates: Listens for network changes and updates state accordingly.
  • Cross-Browser Support: Works with different browser implementations of the Network Information API.
  • SSR Compatibility: Safe for server-side rendering environments.

Installation

Installing Only Current Hooks

npm install @custom-react-hooks/use-network

or

yarn add @custom-react-hooks/use-network

Installing All Hooks

npm install @custom-react-hooks/all

or

yarn add @custom-react-hooks/all

Usage

import React from 'react';
import { useNetwork } from '@custom-react-hooks/use-network';

const NetworkComponent = () => {
  const { online, downlink, effectiveType, rtt, saveData, type } = useNetwork();

  return (
    <div>
      <h2>Network Status</h2>
      <p>Status: {online ? 'Online' : 'Offline'}</p>
      
      {online && (
        <div>
          {downlink && <p>Downlink Speed: {downlink} Mbps</p>}
          {effectiveType && <p>Connection Type: {effectiveType}</p>}
          {rtt && <p>Round Trip Time: {rtt}ms</p>}
          {saveData !== undefined && <p>Save Data Mode: {saveData ? 'Enabled' : 'Disabled'}</p>}
          {type && <p>Network Type: {type}</p>}
        </div>
      )}
    </div>
  );
};

export default NetworkComponent;

API Reference

Returns

An object containing the following properties:

  • online (boolean): Indicates if the user is currently online.
  • downlink (number, optional): Effective bandwidth estimate in megabits per second.
  • downlinkMax (number, optional): Maximum downlink speed in megabits per second.
  • effectiveType ('slow-2g' | '2g' | '3g' | '4g', optional): Effective connection type.
  • rtt (number, optional): Estimated effective round-trip time in milliseconds.
  • saveData (boolean, optional): Indicates if the user has requested a reduced data usage mode.
  • type (string, optional): Connection type ('bluetooth', 'cellular', 'ethernet', 'none', 'wifi', etc.).

Use Cases

  • Adaptive Content Loading: Adjust content quality based on connection speed.
  • Offline Handling: Provide appropriate UI when the user goes offline.
  • Data Usage Optimization: Respect user's data saving preferences.
  • Performance Monitoring: Track network performance for analytics.
  • Progressive Enhancement: Enhance features based on connection quality.

Browser Support

The hook works in all modern browsers. The Network Information API is supported in:

  • Chrome 61+
  • Firefox (limited support)
  • Safari (not supported)
  • Edge 79+

When the Network Information API is not available, the hook will only provide online/offline status.

Contributing

Contributions to enhance useNetwork are welcome. Feel free to submit issues or pull requests to the repository.

License

MIT License - see the LICENSE file for details.