1.0.0-beta.0 • Published 4 years ago

@framini/use-vh v1.0.0-beta.0

Weekly downloads
4
License
MIT
Repository
-
Last release
4 years ago

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-vh

With NPM

npm install @framini/use-vh

Usage

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

  • Demo Site

  • Or you can play around with it locally by running yarn storybook.