Skip to content

NomiAdam/useIsOnline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

NPM JavaScript Style Guide

Install

npm install --save use-is-online

// Or using yarn

yarn add use-is-online

Usage

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

About

Experimental network availability React hook

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published