react-viewport-height
v1.2.2
Published
A utility for React to set 100vh equal to the actual browser inner window height.
Downloads
3,187
Maintainers
Readme
react-viewport-height
A utility for React to set 100vh equal to the actual browser inner window height.
Since vh
has troubles on mobile browsers (primarily because of the address bar), there are several tricks to fix it. This package implements the one from this article.
The solution for this was introduced in the CSS Values and Units Module Level 4 which is widely supported now. Instead of using this package, you can use the dvh
unit if your project doesn't need to support older browsers. Read more about new units.
Usage
npm install react-viewport-height
// index.js
import useVH from 'react-viewport-height';
import './index.css';
const App = () => {
useVH();
return <div className="app" />;
};
/* index.css */
.app {
min-height: calc(var(--vh, 1vh) * 100);
}
Read the documentation for more details. You can also play with a demo.
Support
If you like this package and want to support it, you can do it on Patreon