Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emanuelescarabattoli/react-network-status-hook
A simple React Hook to check if browser is online or offline
https://github.com/emanuelescarabattoli/react-network-status-hook
hook network offline online reactjs status
Last synced: 10 days ago
JSON representation
A simple React Hook to check if browser is online or offline
- Host: GitHub
- URL: https://github.com/emanuelescarabattoli/react-network-status-hook
- Owner: emanuelescarabattoli
- Created: 2019-11-06T21:09:12.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T12:57:49.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T06:23:08.333Z (18 days ago)
- Topics: hook, network, offline, online, reactjs, status
- Language: JavaScript
- Homepage:
- Size: 899 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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 ? Online : Offline
)
};
```# 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 ? Online : Offline
)
};
```