An open API service indexing awesome lists of open source software.

https://github.com/geekskai/react-network-detect

react network detection hooks
https://github.com/geekskai/react-network-detect

Last synced: about 1 year ago
JSON representation

react network detection hooks

Awesome Lists containing this project

README

          

# react-network-detect

![npm bundle size](https://img.shields.io/bundlephobia/minzip/react-network-detect)
[![GitHub license](https://img.shields.io/github/license/geekskai/react-network-detect)](https://github.com/geekskai/react-network-detect/blob/main/LICENSE)
[![npm](https://img.shields.io/npm/v/react-network-detect.svg)](https://www.npmjs.com/package/react-network-detect)
[![npm downloads](https://img.shields.io/npm/dm/react-network-detect.svg)](https://www.npmjs.com/package/react-network-detect)
[![GitHub stars](https://img.shields.io/github/stars/geekskai/react-network-detect)](https://github.com/geekskai/react-network-detect/stargazers)

### react network detection hooks

> If you think it's good, please give a star, this will be the motivation for me to continue to work hard, thank you very much.

## install

`npm install react-network-detect`

or

`yarn add react-network-detect`

## demo
[codesandbox](https://codesandbox.io/s/awesome-lovelace-f9g8lf?file=/src/App.tsx)

## use
### useOnlineEffect
`import { useOnlineEffect } from 'react-network-detect';`

```

function App() {
const { isOnline } = useOnlineEffect();

return (


{
isOnline?'this is online':'oh network error!'
}

);
}

```

### useNetworkStatus

`import { useNetworkStatus } from 'react-network-detect';`

```
const App = () => {
const { effectiveConnectionType } = useNetworkStatus();

let media;
switch(effectiveConnectionType) {
case 'slow-2g':
media = low resolution;
break;
case '2g':
media = medium resolution;
break;
case '3g':
media = high resolution;
break;
case '4g':
media = ...;
break;
default:
media = ...;
break;
}

return

{media}
;
};
```