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 🙏

© 2024 – Pkg Stats / Ryan Hefner

network-connectivity

v1.0.0

Published

A lightweight package for detecting and monitoring network connectivity in web applications.

Downloads

19

Readme

Network Connectivity

npm version License

A lightweight package for detecting and monitoring network connectivity in web applications.

Getting Started

Network Connectivity

Install the package:

Using npm:

$ npm install --save network-connectivity

Using Yarn:

$ yarn add network-connectivity

API Reference

ConnectionBanner Component

The ConnectionBanner component is designed to display online and offline status banners with customizable content. It accepts the following props:

Props

| Prop Name | Type | Default Value | Description | | --------------------- | ------------------------------------- | ----------------- | --------------------------------------------------------------------------------------------- | | alwaysShowBanner | boolean | false | If set to true, the banner will always be displayed, regardless of the online/offline status. | | hideOnlineBannerDelay | number | 2000 | The delay in milliseconds before hiding the online banner after a successful connection is detected. This delay applies when alwaysShowBanner is set to false | | onlineBannerContent | React.ReactElement or string | 'Back online' | The content to display in the online status banner. It can be a React element or a string. | | offlineBannerContent | React.ReactElement or string | 'No connection' | The content to display in the offline status banner. It can be a React element or a string. | | placement | 'top' or 'bottom' | 'top' | The placement of the online status banner within the application UI. Can be set to 'top' or 'bottom'. | | withPortal | boolean | true | If set to true, the ConnectionBanner will use a portal to render the banner. | | className | string | | Additional CSS class names to apply to the ConnectionBanner component. |

CSS Class Names

The ConnectionBanner component supports custom styling through CSS class names. You can use the className prop to apply additional class names to the component. The component itself applies the following class names:

  • connection-banner: The base class name for the ConnectionBanner component.
  • connection-banner-online: Applied when the device is online.
  • connection-banner-offline: Applied when the device is offline.

Example Usage

Here's an example of how you can use the ConnectionBanner component with some custom props:

import { ConnectionBanner } from 'network-connectivity';

const MyComponent = () => {
  return (
    <div>
      <ConnectionBanner alwaysShowBanner={true} />
    </div>
  )
}

useConnection Hook

The useConnection hook allows you to access the network connectivity status within your React components. It returns an object with the following properties:

  • isOnline: A boolean value indicating whether the device is currently online.

Example Usage

import { useConnection } from 'network-connectivity';

const MyComponent = () => {
  const { isOnline } = useConnection();

  return (
    <div>
      <p>Is online: {isOnline ? 'Yes' : 'No'}</p>
    </div>
  );
}

isOnline Function

The isOnline function is a utility function provided by the network-connectivity package. It allows you to programmatically check the network connectivity status.

Example Usage

import { isOnline } from 'network-connectivity';

if (isOnline()) {
  console.log('You are online!');
} else {
  console.log('You are offline.');
}