shadcn-ahooks

useDocumentVisibility

A Hook can tell if the page is visible, refer to [visibilityState API](https://developer.mozilla.org/docs/Web/API/Document/visibilityState)

Overview

A Hook can tell if the page is visible, refer to visibilityState API

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDocumentVisibility.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDocumentVisibility.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDocumentVisibility.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDocumentVisibility.json

A Hook can tell if the page is visible, refer to visibilityState API

Examples

API

const documentVisibility = useDocumentVisibility();

Result

| Property | Description | Type | | | - | -- | | documentVisibility | Whether the document is visible | visible| hidden | prerender | undefined |

On this page