1.0.2 • Published 2 years ago

@enrique.molinari/react-hook-offline-detector v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Custom Hook to Detect Connectivity Status

A react custom hook to detect if you are offline.

Install

$ npm install @enrique.molinari/react-hook-offline-detector

Usage

import { useOffLineDetector } from "@enrique.molinari/react-hook-offline-detector";

const params = {
  pollUrl: "./favicon.ico",
  pollingInterval: 3000,
  fetchTimeout: 5000,
  handleChange: handleChange,
};

function handleChange(status) {
  if (status) {
    console.log("Status changed, we are online :)");
  } else {
    console.log("Status changed, we are offline :(");
  }
}

export function ReactComponent() {
  const isOnLine = useOffLineDetector(params);
  //...

  //use isOnline state variable here
}

By default, the hook will use the following values of the parameters:

paramvalue
pollUrl./favicon.ico
pollingInterval5000
fetchTimeout1000
1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago