use-is-online
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

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

Package Sidebar

Install

npm i use-is-online

Weekly Downloads

1

Version

0.0.5

License

MIT

Unpacked Size

4.89 kB

Total Files

7

Last publish

Collaborators

  • kvasna