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

react-detect-offline

v2.4.5

Published

Offline and Online components for React

Downloads

71,135

Readme

npm npm downloads gzip size badges

Offline and Online components for React

Components that track offline and online state. Render certain content only when online (or only when offline).

import { Offline, Online } from "react-detect-offline";

const App = () => (
  <div>
    <Online>Only shown when you're online</Online>
    <Offline>Only shown offline (surprise!)</Offline>
  </div>
);

Demo

Check out chris.bolin.co/offline for a simple example (source code).

Components

Simple

<Online/> and <Offline/> - Components that render their children only when the browser is online/offline.

<Offline>You're offline right now. Check your connection.</Offline>

Advanced

<Detector render={({ online }) => ...}/> - Component that calls its render prop every time the connection state changes. The render prop is supplied with an object with an online boolean value. Recommended for more complex cases, e.g. when styles need to be changed with connection status.

<Detector
  render={({ online }) => (
    <div className={online ? "normal" : "warning"}>
      You are currently {online ? "online" : "offline"}
    </div>
  )}
/>

Props

<Online/>, <Offline/>, and <Detector/> accept the following props:

| Prop | Type | Description | Default | | ------------------ | ----------- | --------------------------------- | ------------------------------ | | polling | Obj or Bool | Config for polling fallback [1] | [see below] | | polling.enabled | Boolean | Force polling on or off | Depends on the browser [1] | | polling.url | String | URL to pool for connection status | "https://ipv4.icanhazip.com" | | polling.interval | Number | How often (in ms) to poll | 5000 | | polling.timeout | Number | How long (in ms) before timeout | 5000 | | onChange | Function | Called when connection changes | none | | children [2] | Element(s) | Children not Detector | none | | render [3] | Func | Render function Detector only | none |

[1] Polling is only used as a fallback for browsers that don't support the "online" event. Currently these are Chrome on Windows, Firefox on Windows, and Chrome on Linux.

[2] <Online/> and <Offline/> only. <Detector/> will not render children.

[3] <Detector/> only

Browser Support

The web spec we rely on is supported by IE 9+, Chrome 14+, Firefox 41+, and Safari 5+ - that's 94% of worldwide (98% of US) browser traffic. A polling fallback is used for browsers that don't implement the spec in a useful way (see note [1] in the above Props section).

Contributing

This package is maintained by cwise89 (and was initially created by chrisbolin).

PRs are welcome!

  • Test: yarn test
  • Build: yarn build. Make sure you commit the build file (dist/index.js)