1.0.0 • Published 6 years ago

@egauci/react-viewport v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 years ago

Usage

npm install --save @egauci/react-viewport

To use in a component:

import ReactViewport from '@egauci/react-viewport';

const MyComponent = () => (
  <div>
    <p>Current Viewport Values:</p>
    <ReactViewport>
      {
        viewport => (
          <div>
            Scroll: {viewport.scrollX}, {viewport.scrollY}<br />
            Dimensions: {viewport.clientWidth}, {viewport.clientHeight}
          </div>
        )
      }
    </ReactViewport>
  </div>
);

Props:

milli - optional, defaults to 100. The window resize debounce period in milliseconds

render or children - a function that receives the viewport object and returns a React element.

The viewport object has several properties, the useful ones are shown in the example above.