Commit bc1c61b6 authored by Zach Pomerantz's avatar Zach Pomerantz Committed by GitHub

fix: omit document ref (#3685)

parent 446ad3e0
...@@ -12,13 +12,14 @@ function isWindowVisible() { ...@@ -12,13 +12,14 @@ function isWindowVisible() {
* Returns whether the window is currently visible to the user. * Returns whether the window is currently visible to the user.
*/ */
export default function useIsWindowVisible(): boolean { export default function useIsWindowVisible(): boolean {
const [focused, setFocused] = useState<boolean>(isWindowVisible()) const [focused, setFocused] = useState<boolean>(false)
const listener = useCallback(() => { const listener = useCallback(() => {
setFocused(isWindowVisible()) setFocused(isWindowVisible())
}, [setFocused]) }, [setFocused])
useEffect(() => { useEffect(() => {
if (!isVisibilityStateSupported()) return undefined if (!isVisibilityStateSupported()) return undefined
setFocused((focused) => isWindowVisible())
document.addEventListener('visibilitychange', listener) document.addEventListener('visibilitychange', listener)
return () => { return () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment