1.0.0-beta.0 • Published 5 years ago
@framini/use-vh v1.0.0-beta.0
useVh
React Hook for addressing the issue on mobile devices where 100vh doesn't mean what you would expect. This is very noticeable on iOS Safari where we have the address and toolbar on top of the 100vh which generates an undesirable vertical scrollbar.
Install
With Yarn
yarn install @framini/use-vhWith NPM
npm install @framini/use-vhUsage
const fullViewportHeight = () => {
const fullVh = useVh();
return (
<div
style={{
height: `${fullVh}px`,
}}
>
Viewport Height: {fullVh}
</div>
);
};The hook only accepts a number representing the desired vh amount. So for instance if you want 50vh you could do something like:
const halfViewportHeight = () => {
const vh = useVh(50);
return (
<div
style={{
height: `${vh}px`,
}}
>
Viewport Height: {vh}
</div>
);
};Example
Or you can play around with it locally by running
yarn storybook.
1.0.0-beta.1
5 years ago
1.0.0-beta.0
6 years ago