# use-is-online-react

> A smart-ish React hook that returns whether the browser is online or not

Latest version **1.0.1** (published 2023-10-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install use-is-online-react
pnpm add use-is-online-react
yarn add use-is-online-react
bun add use-is-online-react
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-10-09 |
| First published | 2023-10-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bethany Hitch |
| Maintainers | dfoverdx |
| Keywords | react, react-hook, is-online, useIsOnline, use-is-online, react hook, online, polling |

## Links

- npm: https://www.npmjs.com/package/use-is-online-react
- Repository: https://github.com/dfoverdx/use-is-online-react
- Homepage: https://github.com/dfoverdx/use-is-online-react#readme
- Issues: https://github.com/dfoverdx/use-is-online-react/issues
- npm.io page: https://npm.io/package/use-is-online-react

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-10-09
- 1.0.0 — 2023-10-06

## README

use-is-online-react
===================

A smart-ish React hook to determine if the user's device is online by checking for an internet connection. Improves on other available packages by optionally using a polling mechanism to determine if the computer is online.

Installation
------------

Install the package using npm or yarn:

```bash
npm install use-is-online-react
# or
yarn add use-is-online-react
```

Usage
-----

```javascript
import useIsOnline from 'use-is-online-react';

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

  return <div>{isOnline ? 'Online' : 'Offline'}</div>;
};
```

### Options

#### `useIsOnline(poll: boolean = true): boolean`

- `poll` (optional): A boolean indicating whether to use a smart polling mechanism to check for online status. Default is `true`. When set to `true`, it periodically polls `//captive.apple.com/hotspot-detect.html` (or whatever you set `useIsOnline.pollingUrl` to) to determine if the computer is online. When set to `false`, it simply uses `navigator.online`.

### Properties

- `useIsOnline.pollingInterval: number`: The interval (in milliseconds) at which to poll the `useIsOnline.pollingUrl` endpoint. Default is `5000` (5 seconds). Must be at least `1000`, but recommended to be at least `5000`. Value is ignored if `poll` is set to `false`.  Note: changes to this value will not go into effect until all polling has stopped and restarted.

- `useIsOnline.pollingUrl: string`: The URL to poll to determine if the computer is online. Default is `'//captive.apple.com/hotspot-detect.html'`. If you want to detect internet connectivity to your server, change this value to an HTTP/HTTPS GET endpoint provided by your server. The response body is ignored.

- `useIsOnline.debug: boolean`: A boolean indicating whether to log debug messages to the console. Default is `false`.

Peer Dependencies
-----------------

This package has the following peer dependencies:

- React version 18 or higher

Browser Support
---------------

This package uses the `fetch()` API, so it targets browsers supporting ES2015 or higher.

License
-------

This package is licensed under the [MIT License](LICENSE).

Credits
-------

Thanks to the npm package [is-online](https://github.com/sindresorhus/is-online) for the idea of using the `https://captive.apple.com/hotspot-detect.html` endpoint to determine if the computer is online.

---
_Source: https://npm.io/package/use-is-online-react · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
