1.0.16 • Published 5 years ago

react-network-status-hook v1.0.16

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

React Network Status Hook

A simple React Hook to check if browser is online or offline.

Installation

To install the package run the following command.

npm install react-network-status-hook

Usage with default parameters

Just import the Hook and use it to detect offline or online status. The check will be done by send a request every 500 milliseconds to https://dns.google/ but you can change parameters as described in the next section.

import React from "react";
import useNetworkStatus from "react-network-status-hook";

const MyComponent = () => {
  const isOnline = useNetworkStatus();

  return (
    isOnline ? <span>Online</span> : <span>Offline</span>
  )
};

Usage with custom parameters

You can specify custom parameters for the check as shown here.

import React from "react";
import useNetworkStatus from "react-network-status-hook";

const MyComponent = () => {
  const isOnline = useNetworkStatus("http://localhost:8000/", 1000);

  return (
    isOnline ? <span>Online</span> : <span>Offline</span>
  )
};
1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago