1.1.4 • Published 2 years ago

@kokojer/react-use-document-visibility v1.1.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

React-use-document-visibility

This hook checks whether the browser tab the user is currently on is active and how many times the user has left the page. Also provides a function where you can subscribe to changes in tab activity.

Example

import React, {useEffect} from 'react'
import { useDocumentVisibility } from '@kokojer/react-use-document-visibility'

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

    useEffect(() => {
        onVisibilityChange((isVisible) => {
            console.log('first handler', isVisible)
        });
        onVisibilityChange((isVisible) => {
            console.log('second handler', isVisible)
        });
    }, [])

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

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago