react-use-is-online
Advanced tools
Comparing version 1.0.3 to 1.0.4
"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>} |
9865
11
162
67