# @render-props/rect

> A state container which provides an interface for retrieving the bounding client rect of a referenced element. The bounding client rect will update each time the window resizes - a behavior which can be turned off by setting the prop `recalcOnWindowResize

Latest version **0.1.22** (published 2019-03-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @render-props/rect
pnpm add @render-props/rect
yarn add @render-props/rect
bun add @render-props/rect
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.22 |
| Published | 2019-03-20 |
| First published | 2018-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 15.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 36 |
| Author | Jared Lunde |
| Maintainers | jaredlunde |
| Keywords | react, render props, function as child, hoc, state container, rect, domrect, getBoundingClientRect, size, width, height |

## Links

- npm: https://www.npmjs.com/package/@render-props/rect
- Repository: https://github.com/jaredlunde/render-props/tree/master/packages/rect
- npm.io page: https://npm.io/package/@render-props/rect

## Dependencies (3)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.4.0
- [@render-props/events](https://npm.io/package/@render-props/events.md) ^0.1.2
- [@render-props/throttle](https://npm.io/package/@render-props/throttle.md) ^0.1.5

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.1.22 (latest) — 2019-03-20
- 0.1.21 — 2019-01-31
- 0.1.20 — 2019-01-12
- 0.1.19 — 2018-12-29
- 0.1.18 — 2018-09-11
- 0.1.17 — 2018-09-10
- 0.1.16 — 2018-08-21
- 0.1.15 — 2018-08-20
- 0.1.14 — 2018-08-18
- 0.1.13 — 2018-08-18
- 0.1.12 — 2018-08-18
- 0.1.11 — 2018-05-15
- 0.1.10 — 2018-05-15
- 0.1.9 — 2018-03-26
- 0.1.8 — 2018-03-22
- … 8 more at https://npm.io/package/@render-props/rect/versions

## README

# Rect
A state container which provides an interface for retrieving the bounding
client rect of a referenced element. The bounding client rect will update
each time the window resizes - a behavior which can be turned off by setting
the prop `recalcOnWindowResize` to `false`. It doesn't provide values for `x` and
`y`, as IE, Edge and Safari don't have them as part of their `DOMRect`.


### Installation
```yarn add @render-props/rect``` or ```npm i @render-props/rect```


____


## Usage
```js
import Rect from '@render-props/rect'

function DivWithRect (props) {
  return (
    <Rect>
      ({rectRef, recalcRect, top, right, bottom, left, width, height}) => (
        <div ref={rectRef}>
          <div>
            My width: {width}
          </div>
          <div>
            My height: {height}
          </div>
          <div>
            My position: {JSON.stringify({top, right, bottom, left})}
          </div>
        </div>
      )
    </Rect>
  )
}
```

____

## Props
- `recalcOnWindowResize {bool}`: if `true`, this component will update itself
each time a window resize event is detected. Defaults to `true`.
- `withCoords {bool}`: if `true`, this component will provide its child function
with unpacked arguments for its bounding client rect, i.e.
`{top, right, bottom, left, width, height}`. If `false`, it will provide a
function `getRect` instead which will return the same object just mentioned.
Defaults to `true`.

## Render Props

#### Ref
- `rectRef` (`element`)
  - This `ref` must be provided to whatever element you are trying to receive the
    bounding client rect for. e.g. `<div ref={rectRef}>`

#### Methods
- `recalcRect`
  - remeasures the element bound to `rectRef`
- `getRect`
  - only present if `withCoords` is set to `false`. Returns the bounding client
    rect object.

#### State
Note: these are only provided if `withCoords` is `true`.

- `top {number}`: the top coordinate value of the `DOMRect`
- `right {number}`: the right coordinate value of the `DOMRect`
- `bottom {number}`: the bottom coordinate value of the `DOMRect`
- `left {number}`: the left coordinate value of the `DOMRect`
- `width {number}`: the width of the `DOMRect`
- `height {number}`: the height of the `DOMRect`

---
_Source: https://npm.io/package/@render-props/rect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
