@stackmeister/react-use-document-visibility
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

@stackmeister/react-use-document-visibility

A hook that checks if a screen is currently rendered by its system or not.

Mostly relies on document.hidden and the visibilitychange event.

This hook can help with green coding, to stop animations and heavy stuff when the app is not currently on top or rendered.

Install

// Yarn
yarn add @stackmeister/react-use-document-visibility

// NPM
npm i @stackmeister/react-use-document-visibility

TypeScript typings are included (No @types/ package needed)

Usage

import useDocumentVisibility from '@stackmeister/react-use-document-visibility'

const App = () => {
  const { visible } = useDocumentVisibility()

  return (
    <div>
      {visible && <HeavyComponent />}
    </div>
  )
}

Readme

Keywords

none

Package Sidebar

Install

npm i @stackmeister/react-use-document-visibility

Weekly Downloads

0

Version

0.1.5

License

MIT

Unpacked Size

7.35 kB

Total Files

7

Last publish

Collaborators

  • torbenkoehn