mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-25 10:02:27 -04:00
* Test * Add pretty formatting * Fix Tests * Fix Tests * Fix Tests * Fix * Add pretty formatting fix * Fix * Test * Fix tests * Clean typeckech * Add prettier check * Fix api tsconfig * Fix api tsconfig * Fix tsconfig * Fix * Fix * Prettier
20 lines
510 B
TypeScript
20 lines
510 B
TypeScript
import {useEffect, useState} from 'react'
|
|
|
|
export const useIsPageVisible = () => {
|
|
const [isPageVisible, setIsPageVisible] = useState(
|
|
typeof document !== 'undefined' ? !document.hidden : true,
|
|
)
|
|
|
|
useEffect(() => {
|
|
const updateVisibility = () => {
|
|
setIsPageVisible(!document.hidden)
|
|
}
|
|
document.addEventListener('visibilitychange', updateVisibility)
|
|
return () => {
|
|
document.removeEventListener('visibilitychange', updateVisibility)
|
|
}
|
|
}, [])
|
|
|
|
return isPageVisible
|
|
}
|