@framini/use-vh
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.0 • Public • Published

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

You can play around with it by running StoryBook.

yarn storybook

Readme

Keywords

none

Package Sidebar

Install

npm i @framini/use-vh

Weekly Downloads

37

Version

1.0.0-beta.0

License

MIT

Unpacked Size

17.5 kB

Total Files

15

Last publish

Collaborators

  • framini