useDocumentVisibility

Tags:

A React Hook that returns document.visibilityState.

Demo

Try to switch to another tab or minimize the window to see the title change.

Source
Visibility:
visible

Usage

See API for more details.

Source

Click links below to view source on GitHub.

API

const visibility = useDocumentVisibility(callback)

Callback

A callback function that will be called when the visibility state changes.

export type UseDocumentVisibilityCallback = (state: DocumentVisibilityState, event: Event) => void

Returns

export type DocumentVisibilityState = 'hidden' | 'visible'