Files
Folo/packages/internal/hooks/src/usePageVisibility.ts
T
Innei 4d746522f1 refactor: remove unused files and clean up project structure
- Deleted obsolete configuration files and unused components across various packages.
- Updated package.json files to reflect the removal of dependencies.
- Cleaned up code by removing unnecessary exports and unused imports in multiple modules.

Signed-off-by: Innei <tukon479@gmail.com>
2025-04-28 20:58:51 +08:00

18 lines
472 B
TypeScript

import { useLayoutEffect, useState } from "react"
export function usePageVisibility() {
const [isPageVisible, setIsPageVisible] = useState(!document.hidden)
useLayoutEffect(() => {
const handleVisibility = () => {
setIsPageVisible(!document.hidden)
}
document.addEventListener("visibilitychange", handleVisibility)
return () => {
document.removeEventListener("visibilitychange", handleVisibility)
}
}, [])
return isPageVisible
}