You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

react-detect-offline-api

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-detect-offline-api - npm Package Compare versions

Comparing version

to
1.0.2

7

dist/index.d.ts

@@ -11,4 +11,8 @@ /**

onOffline?: Function;
initialStatusCallback?: (status: boolean) => void;
};
export default class ReactDetectOfflineAPI extends React.Component<Props> {
declare type State = {
online: boolean | null;
};
export default class ReactDetectOfflineAPI extends React.Component<Props, State> {
private interval;

@@ -24,1 +28,2 @@ state: {

}
export {};

18

dist/index.es.js

@@ -53,12 +53,22 @@ import { createElement, Fragment, Component } from 'react';

timeout(3000, fetch(apiUrl).then(function () {
_this.setState({ online: true }, function () {
if (_this.props.onOnline) {
_this.setState(function (_a) {
var online = _a.online;
if (_this.props.onOnline && online === false) {
_this.props.onOnline();
}
if (_this.props.initialStatusCallback && online === null) {
_this.props.initialStatusCallback(true);
}
return { online: true };
});
})).catch(function () {
_this.setState({ online: false }, function () {
if (_this.props.onOffline) {
_this.setState(function (_a) {
var online = _a.online;
if (_this.props.onOffline && online === true) {
_this.props.onOffline();
}
if (_this.props.initialStatusCallback && online === null) {
_this.props.initialStatusCallback(false);
}
return { online: false };
});

@@ -65,0 +75,0 @@ });

@@ -57,12 +57,22 @@ 'use strict';

timeout(3000, fetch(apiUrl).then(function () {
_this.setState({ online: true }, function () {
if (_this.props.onOnline) {
_this.setState(function (_a) {
var online = _a.online;
if (_this.props.onOnline && online === false) {
_this.props.onOnline();
}
if (_this.props.initialStatusCallback && online === null) {
_this.props.initialStatusCallback(true);
}
return { online: true };
});
})).catch(function () {
_this.setState({ online: false }, function () {
if (_this.props.onOffline) {
_this.setState(function (_a) {
var online = _a.online;
if (_this.props.onOffline && online === true) {
_this.props.onOffline();
}
if (_this.props.initialStatusCallback && online === null) {
_this.props.initialStatusCallback(false);
}
return { online: false };
});

@@ -69,0 +79,0 @@ });

{
"name": "react-detect-offline-api",
"version": "1.0.1",
"version": "1.0.2",
"description": "Detect whether your API is online of offline",

@@ -5,0 +5,0 @@ "author": "jvorcak",

@@ -30,2 +30,5 @@ # react-detect-offline-api

}}
initialStatusCallback={status => {
console.log('Initial status ', status ? 'online' : 'offline')
}}
render={({ online }) =>

@@ -50,4 +53,5 @@ online

| render | false | Function | We're using [Render Props](https://reactjs.org/docs/render-props.html) to render online of offline component. See an example for more info. |
| onOnline | false | Function | Called once an online API is detected |
| onOffline | false | Function | Called once an offline API is detected |
| onOnline | false | Function | Called once an API becomes online and was offline |
| onOffline | false | Function | Called once an API becomes offline and was online |
| initialStatusCallback | false | (status: boolean) => void | Calledback that returnes an initial status |

@@ -54,0 +58,0 @@ ## License

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet