Created
May 2, 2023 17:23
-
-
Save 8mist/5b3dec3a1d3d031b7281e21bf91d7d93 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from 'react'; | |
export default function RealViewport() { | |
useEffect(() => { | |
function onWindowResize() { | |
const vh = window.innerHeight * 0.01; | |
document.documentElement.style.setProperty('--vh', `${vh}px`); | |
} | |
window.addEventListener('resize', onWindowResize, false); | |
onWindowResize(); | |
return () => { | |
window.removeEventListener('resize', onWindowResize, false); | |
}; | |
}, []); | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment