A React hook for detecting if you are online or offline.
npm install react-use-is-onlineSimple React Hook for checking if you're connected to the internet.
Read about Hooks feature.
  ![Linux Build Status]
yarn add react-use-is-online
`#### Installing with NPM
`
npm install react-use-is-online
`
Demo
https://stackblitz.com/edit/react-use-is-online1Examples
Using useIsOnline to display different messages if connectivity is present.
`javascript
import React, { Fragment } from 'react';
import { useIsOnline } from 'react-use-is-online';
import InternetEnabledFeature from './InternetConnectedFeature';
import OfflineEnabledFeature from './OfflineEnabledFeature';
const BasicApp = () => {
const { isOnline, isOffline, error } = useIsOnline();
return (
{isOnline ? We're online! : Uh-oh looks like you should connect to the internet }
{isOffline ? We're offline! You can still post great cat photos! : We're not online. }
);
};
`Using useIsOnline to enable certain features based on connectivity.
`javascript
import React, { Fragment } from 'react';
import { useIsOnline } from 'react-use-is-online';
import InternetEnabledFeature from './InternetConnectedFeature';
import OfflineEnabledFeature from './OfflineEnabledFeature';
const AdvancedApp = () => {
const { isOnline, isOffline, error } = useIsOnline();
return (
{
isOnline ? :
}
);
};
``