use-is-online
v0.0.5
Published
Experimental network availability React hook.
Downloads
14
Maintainers
Readme
useIsOnline
Experimental React hook utility to check whether internet connection is available or not.
Uses both browser navigator.onLine to check for local connection, then confirms with public-ip library call
TODO: test coverage
Install
npm install --save use-is-online
// Or using yarn
yarn add use-is-onlineUsage
import React from 'react';
import { ifElse, always } from 'ramda';
import { isTruthy } from 'ramda-extension';
import useIsOnline from 'use-is-online';
const options = {
https: true,
delay: 3000
};
const checkConnectionDelay = 30000;
const getNetworkStatus = ifElse(isTruthy, always('online'), always('offline'));
const App = () => {
const { isOnline } = useIsOnline(options, checkDelay);
return (
<h1>{ `You are ${ getNetworkStatus(isOnline) }` }<h1>
);
};
export default App;License
MIT © NomiAdam
