This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@wbe/use-bounding-client-rect
TypeScript icon, indicating that this package has built-in type declarations

2.7.1 • Public • Published

@wbe/use-bounding-client-rect

This React hook allow to get dynamically getBoundClientRect of any React Ref.

Installation

$ npm install -s @wbe/use-bounding-client-rect

How to use

Basic usage:

// ...
import { useBoundingClientRect } from "@wbe/use-window-size";

const App = () => {
  // get ref
  const rootRef = useRef();
  // get ref properties
  const refRect = useBoundingClientRect(rootRef);

  return (
    <div ref={rootRef}>
      {refRect.x}, {refRect.y} ...
    </div>
  );
};

Parameters

params type description default value
pRef MutableRefObject element ref /
pListener EListener kind of listener EListener.ON_INIT

pListener options are:

  • ON_INIT: listen rect only on init
  • ON_SCROLL: listen rect on init + scroll
  • ON_RESIZE: listen rect on init + resize
  • ON_SCROLL_AND_RESIZE: listen rect on init + scroll + resize

Returned

The hook return an object (ClientRect interface):

{
  "x": number,
  "y": number,
  "width": number,
  "height": number,
  "top": number,
  "right": number,
  "bottom": number,
  "left": number
}

Readme

Keywords

Package Sidebar

Install

npm i @wbe/use-bounding-client-rect

Weekly Downloads

3

Version

2.7.1

License

MIT

Unpacked Size

42.4 kB

Total Files

18

Last publish

Collaborators

  • willybe