1.0.0 • Published 2 years ago

hook-use-document-visibility v1.0.0

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

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

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>
  );
};
1.0.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago