@ac-hooks/use-connectivity

0.0.5 • Public • Published

@ac-hooks/use-connectivity

A custom React Hook that provides internet connectivity status using browsers' online/offline events.

npm version

Installation

$ npm i @ac-hooks/use-connectivity

or

$ yarn add @ac-hooks/use-connectivity

Usage

Here is a basic usage:

import useConnectivity from '@ac-hooks/use-connectivity';

const { isOnline } = useConnectivity();

if (isOnline) {
  // you're back!
} else {
  // oh no! I can't see you!
}

How to test

You can check it toggling the Offline checkbox in the Network pane of your developer tools.

Live demo

You can view/edit the sample code above on CodeSandbox.

Edit demo app on CodeSandbox

Parameters

This hook doesn't accept any parameter.

Return

Parameter Type Description
isOnline bool Whether you are online or not

License

MIT Licensed

Contributions of any kind welcome!

Readme

Keywords

none

Package Sidebar

Install

npm i @ac-hooks/use-connectivity

Weekly Downloads

1

Version

0.0.5

License

MIT

Unpacked Size

4.15 kB

Total Files

4

Last publish

Collaborators

  • abdullahceylan