Created
June 20, 2019 10:04
-
-
Save srph/eec70a007d2b1df0f483d29b0ab5fbff to your computer and use it in GitHub Desktop.
React: 100vh css variable workaround for mobile (https://css-tricks.com/the-trick-to-viewport-units-on-mobile/)
This file contains hidden or 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' | |
import useWindowSize from 'react-use/lib/useWindowSize' | |
/** | |
* @NOTE Don't mount this twice; only on the root node. | |
*/ | |
function WindowVhSetter() { | |
const {height} = useWindowSize() | |
useEffect(() => { | |
document.body.style.setProperty('--window-vh', `${height}px`) | |
}, [height]) | |
return null | |
} | |
export default WindowVhSetter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment