Skip to content

Latest commit

 

History

History
67 lines (40 loc) · 1.25 KB

README.md

File metadata and controls

67 lines (40 loc) · 1.25 KB

use-page-visibility

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

Demo

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

Prerequisite

Installation

npm install use-page-visibility

or with yarn

yarn add use-page-visibility

Usage

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

function App() {
  const handleVisibilityChange = visible => {
    return visible ? playVideo() : 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 - React hooks implementation of Google's "Thanos" easter egg

Author

Olushi Luqman Opemipo

License

This project is licensed under MIT