fix: omit document ref (#3685)

This commit is contained in:
Zach Pomerantz 2022-04-07 15:05:11 -07:00 committed by GitHub
parent 446ad3e0d4
commit bc1c61b63a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -12,13 +12,14 @@ function isWindowVisible() {
* Returns whether the window is currently visible to the user.
*/
export default function useIsWindowVisible(): boolean {
const [focused, setFocused] = useState<boolean>(isWindowVisible())
const [focused, setFocused] = useState<boolean>(false)
const listener = useCallback(() => {
setFocused(isWindowVisible())
}, [setFocused])
useEffect(() => {
if (!isVisibilityStateSupported()) return undefined
setFocused((focused) => isWindowVisible())
document.addEventListener('visibilitychange', listener)
return () => {