Skip to Content

usePageVisibility

Exports Size
loading...
Gzip Size
loading...
Brotli Size
Source Code
View on GitHub
Docs
Edit this page

Simple React Hook for checking if the app is in the foreground or background. It uses useSyncExternalStore under the hood to support React 18 concurrent rendering and server-side rendering.

Usage

import { usePageVisibility } from 'foxact/use-page-visibility'; usePageVisibility(); // Returns a boolean value