Skip to content

Instantly share code, notes, and snippets.

@8mist
Created May 2, 2023 17:23
Show Gist options
  • Save 8mist/5b3dec3a1d3d031b7281e21bf91d7d93 to your computer and use it in GitHub Desktop.
Save 8mist/5b3dec3a1d3d031b7281e21bf91d7d93 to your computer and use it in GitHub Desktop.
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