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 - npm Package Compare versions

Comparing version 2.1.1 to 2.1.2

6

dist/index.js

@@ -26,2 +26,4 @@ "use strict";

var inBrowser = typeof navigator !== "undefined";
// these browsers don't fully support navigator.onLine, so we need to use a polling backup

@@ -78,3 +80,3 @@ var unsupportedUserAgentsPattern = /Windows.*Chrome|Windows.*Firefox|Linux.*Chrome/;

var defaultPollingConfig = {
enabled: unsupportedUserAgentsPattern.test(navigator.userAgent),
enabled: inBrowser && unsupportedUserAgentsPattern.test(navigator.userAgent),
url: "https://ipv4.icanhazip.com/",

@@ -96,3 +98,3 @@ timeout: 5000,

_this.state = {
online: typeof navigator.onLine === "boolean" ? navigator.onLine : true
online: inBrowser && typeof navigator.onLine === "boolean" ? navigator.onLine : true
};

@@ -99,0 +101,0 @@ // bind event handlers

{
"name": "react-detect-offline",
"version": "2.1.1",
"version": "2.1.2",
"description": "Offline and Online components for React",

@@ -45,3 +45,9 @@ "main": "dist/index.js",

},
"keywords": ["react", "offline", "online", "detect", "disconnect"],
"keywords": [
"react",
"offline",
"online",
"detect",
"disconnect"
],
"jest": {

@@ -48,0 +54,0 @@ "collectCoverageFrom": [

@@ -27,8 +27,24 @@ [![npm](https://img.shields.io/npm/v/react-detect-offline.svg)](https://www.npmjs.com/package/react-detect-offline)

`<Online/>` - Component that renders its children only when the browser is online. _Recommended for simple use cases._
#### Simple
`<Offline/>` - Component that renders its children only when the browser is not online. _Recommended for simple use cases._
`<Online/>` and `<Offline/>` - Components that render their children only when the browser is online/offline.
```jsx
<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._
```jsx
<Detector
render={({ online }) => (
<div className={online ? "normal" : "warning"}>
You are currently {online ? "online" : "offline"}
</div>
)}
/>
```
### Props

@@ -58,1 +74,8 @@

The [web spec](https://developer.mozilla.org/en-US/docs/Online_and_offline_events) we rely on is supported by IE 9+, Chrome 14+, Firefox 41+, and Safari 5+ - that's [94% of worldwide (98% of US)](http://caniuse.com/#feat=online-status) 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
PRs are welcome!
* Test: `yarn test`
* Build: `yarn build`. Make sure you commit the build file (`dist/index.js`)
import { Component, isValidElement, Children, createElement } from "react";
import PropTypes from "prop-types";
const inBrowser = typeof navigator !== "undefined";
// these browsers don't fully support navigator.onLine, so we need to use a polling backup

@@ -51,3 +53,3 @@ const unsupportedUserAgentsPattern = /Windows.*Chrome|Windows.*Firefox|Linux.*Chrome/;

const defaultPollingConfig = {
enabled: unsupportedUserAgentsPattern.test(navigator.userAgent),
enabled: inBrowser && unsupportedUserAgentsPattern.test(navigator.userAgent),
url: "https://ipv4.icanhazip.com/",

@@ -63,3 +65,6 @@ timeout: 5000,

this.state = {
online: typeof navigator.onLine === "boolean" ? navigator.onLine : true
online:
inBrowser && typeof navigator.onLine === "boolean"
? navigator.onLine
: true
};

@@ -66,0 +71,0 @@ // bind event handlers

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