Socket
Socket
Sign inDemoInstall

react-use-is-online

Package Overview
Dependencies
114
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.0.4

lib/index.test.d.ts

12

lib/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
var NOT_BROWSER_ERROR = 'useIsOnline only works in a browser environment.';
var NOT_BROWSER_ENV_ERROR = 'useIsOnline only works in a browser environment.';
var notABrowserEnv = typeof window === 'undefined';
var navigatorNotPresent = typeof navigator === 'undefined';
var useIsOnline = function () {
var _a = react_1.useState(window.navigator.onLine), isOnline = _a[0], setOnlineStatus = _a[1];
if (!window) {
if (notABrowserEnv || navigatorNotPresent) {
return {
error: NOT_BROWSER_ERROR,
error: NOT_BROWSER_ENV_ERROR,
isOnline: false,
isOffline: false
isOffline: false,
};
}
var _a = react_1.useState(window.navigator.onLine), isOnline = _a[0], setOnlineStatus = _a[1];
react_1.useEffect(function () {

@@ -15,0 +17,0 @@ var toggleOnlineStatus = function () { return setOnlineStatus(window.navigator.onLine); };

{
"name": "react-use-is-online",
"version": "1.0.3",
"version": "1.0.4",
"description": "A React hook for detecting if you are online or offline.",

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

@@ -36,3 +36,2 @@ # use-is-online

<Fragment>
{error ? <div> there's an error {error} </div> : null }
{isOnline ? <div> We're online! </div> : <div> Uh-oh looks like you should connect to the internet </div>}

@@ -39,0 +38,0 @@ {isOffline ? <div> We're offline! You can still post great cat photos! </div> : <div> We're not online. </div>}

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc