Socket
Socket
Sign inDemoInstall

react-detect-offline

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-detect-offline

Offline and Online components for React


Version published
Weekly downloads
14K
decreased by-22%
Maintainers
1
Weekly downloads
 
Created
Source

npm gzip size badges 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

<Online/> - Component that renders its children only when the browser is online. Recommended for simple use cases.

<Offline/> - Component that renders its children only when the browser is not online. Recommended for simple use cases.

<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.

Props

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

PropTypeDescriptionDefault
pollingObj or BoolConfig for polling fallback [1][see below]
polling.enabledBooleanForce polling on or offDepends on the browser [1]
polling.urlStringURL to pool for connection status"https://ipv4.icanhazip.com"
polling.intervalNumberHow often (in ms) to poll5000
polling.timeoutNumberHow long (in ms) before timeout5000
onChangeFunctionCalled when connection changesnone
children [2]Element(s)Children not Detectornone
render [3]FuncRender function Detector onlynone

[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).

Keywords

FAQs

Package last updated on 21 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc