# hook-use-document-visibility

> This hook checks if the browser tab the user is in is active and how many times the page has been visited by the user

Latest version **1.0.0** (published 2022-06-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install hook-use-document-visibility
pnpm add hook-use-document-visibility
yarn add hook-use-document-visibility
bun add hook-use-document-visibility
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-06-19 |
| First published | 2022-06-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | jamila_sh |
| Maintainers | jamila_sh |
| Keywords | react, hook, document, visibility |

## Links

- npm: https://www.npmjs.com/package/hook-use-document-visibility
- Repository: https://github.com/JamilaShakurova/use-document-visibility
- Issues: https://github.com/JamilaShakurova/use-document-visibility/issues
- npm.io page: https://npm.io/package/hook-use-document-visibility

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^18.1.0
- [react-dom](https://npm.io/package/react-dom.md) ^18.1.0

## 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.0 (latest) — 2022-06-19
- 0.1.4 — 2022-06-11
- 0.1.3 — 2022-06-11
- 0.1.2 — 2022-06-11
- 0.1.1 — 2022-06-10
- 0.1.0 — 2022-06-08

## README

# useDocumentVisibility

This hook checks if the browser tab the user is in is active 
and how many times the page has been visited by the user

---

## Example

```jxs
import React from 'react'
import useDocumentVisibility from 'hook-use-document-visibility'

const LeaveTabCounter = () => {
  const { count, visible, onVisibilityChange } = useDocumentVisibility();

  useEffect(() => {
    onVisibilityChange((isVisible) => {
      //...
    });
    onVisibilityChange((isVisible) => {
      //...
    });
  }, [])

  return (
    <div>
      <span>
        You have left the page: {count} times
        Is the tab active? {visible ? 'yes' : 'no'}
      </span>
    </div>
  );
};
```

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