2.7.1 • Published 2 years ago

@wbe/use-bounding-client-rect v2.7.1

Weekly downloads
274
License
MIT
Repository
github
Last release
2 years ago

@wbe/use-bounding-client-rect

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

npm.io npm.io npm.io npm.io npm.io

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

paramstypedescriptiondefault value
pRefMutableRefObjectelement ref/
pListenerEListenerkind of listenerEListener.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
}
2.7.1

2 years ago

2.7.0

2 years ago

2.4.0

3 years ago

2.3.0

3 years ago

2.2.0-alpha.0

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

2.0.0-alpha.11

3 years ago

2.0.0-alpha.10

3 years ago

2.0.0-alpha.7

3 years ago

2.0.0-alpha.6

3 years ago

2.0.0-alpha.3

3 years ago

2.0.0-alpha.0

3 years ago

2.0.0-alpha.1

3 years ago

2.0.0-alpha.2

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.2

4 years ago

1.4.2-alpha.0

4 years ago

1.4.1

4 years ago

1.4.0-alpha.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0-alpha.0

4 years ago

1.0.0-alpha.0

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.26

4 years ago

0.0.25

4 years ago

0.0.24

4 years ago

0.0.22

4 years ago

0.0.23

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago