# use-page-visibility

> Dead-simple, zero-config React hook lib for detecting page visibility 👁️

Latest version **3.0.2** (published 2019-09-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-page-visibility
pnpm add use-page-visibility
yarn add use-page-visibility
bun add use-page-visibility
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2019-09-10 |
| First published | 2019-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 48 |
| Author | Luqman Olushi |
| Maintainers | codeshifu |
| Keywords | react, hooks, page visiblity, visibilityState |

## Links

- npm: https://www.npmjs.com/package/use-page-visibility
- Repository: https://github.com/codeshifu/use-page-visibility
- Homepage: https://github.com/codeshifu/use-page-visibility#readme
- Issues: https://github.com/codeshifu/use-page-visibility/issues
- npm.io page: https://npm.io/package/use-page-visibility

## 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

- 3.0.2 (latest) — 2019-09-10
- 3.0.1 — 2019-09-05
- 3.0.0 — 2019-09-05
- 2.0.0 — 2019-09-04
- 1.0.0 — 2019-09-04

## README

# use-page-visibility

Dead-simple, React hook lib for detecting page visibility 👁️

## Demo
https://use-page-visibility.netlify.com/

## Prerequisite

- [React 16.8+](https://reactjs.org/blog/2019/02/06/react-v16.8.0.html)

## Installation

```bash
npm install use-page-visibility
```

or with yarn

```bash
yarn add use-page-visibility
```

## Usage

```jsx
...
import usePageVisibility from 'use-page-visibility';

function App() {
  const handleVisibilityChange = (visible) => {
    if (visible) playVideo();
    else pauseVideo();
  }

  usePageVisibility(handleVisibilityChange); 

  return ...
}
```

## Api

`usePageVisibility(fn, delay)`

### fn

Type: `function`

Callback function to run when page visibility changes. A boolean value (indicating whether the page is visible or not) will be passed as an argument to this function.

### delay (optional)

Type: `number`

Number of milliseconds to wait before responding to page visibility change

## Related

- [react-thanos](https://github.com/codeshifu/react-thanos) - React hooks implementation of Google's "Thanos" easter egg

## Author

[Olushi Luqman Opemipo](https://twitter.com/codeshifu)

## License

This project is licensed under [MIT](https://github.com/codeshifu/use-page-visibility/blob/master/LICENSE)

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