v6.0.35

use-document-visibility

Detect if current tab is active
Import

Usage

use-document-visibility hook returns current document.visibilityState – it allows to detect if current tab is active:

Switch to another tab to see document title change
import { Text } from '@asuikit/core';
import { useDocumentTitle, useDocumentVisibility } from '@asuikit/hooks';
function Demo() {
const documentState = useDocumentVisibility();
useDocumentTitle(`Document is ${documentState}`);
return <Text>Switch to another tab to see document title change</Text>;
}

Definition

function useDocumentVisibility(): 'visible' | 'hidden';