Hook to check page visibility #1427
matheusvellone
started this conversation in
Feature requests
Replies: 2 comments
-
Implemented this hook on my app, but it would be cool to have this on Mantine too 😄 import { useEffect, useState } from "react"
export default () => {
const [isVisible, setIsVisible] = useState(!document.hidden)
const updateVisibility = () => setIsVisible(!document.hidden)
useEffect(() => {
document.addEventListener('visibilitychange', updateVisibility, false)
return () => document.removeEventListener('visibilitychange', updateVisibility)
})
return isVisible
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
We've already added this hook, it will be available in 4.3 release |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Create a new hook which relies on
document.hidden
. It provides a cool API to check if the page is currently visible. It works with multiple monitors also.Refs:
Beta Was this translation helpful? Give feedback.
All reactions