An open API service indexing awesome lists of open source software.

https://github.com/alexeyraspopov/use-bounding-rect

A tiny React hook to access DOM Rect of an element dynamically.
https://github.com/alexeyraspopov/use-bounding-rect

Last synced: 5 months ago
JSON representation

A tiny React hook to access DOM Rect of an element dynamically.

Awesome Lists containing this project

README

        

# use-bounding-rect

npm install use-bounding-rect

A tiny React hook to access [DOM Rect][gbcr] of an element dynamically. Uses [`ResizeObserver`][ro]
under the hood to update state.

```jsx
import { useBoundingRect } from "use-bounding-rect";

function Wrapper() {
let ref = useRef(null);
let rect = useBoundingRect(ref);
return (


{rect != null ? : null}

);
}
```

[gbcr]: https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect
[ro]: https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver