# @render-props/image-props

> A state container which provides an interface for getting the natural size, rendered size and orientation from `` elements.

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

## Install

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

## 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.18 |
| Published | 2019-03-20 |
| First published | 2018-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 12.6 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, image size |

## Links

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

## Dependencies (3)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.4.0
- [cancelable-promise](https://npm.io/package/cancelable-promise.md) ^2.4.1
- [@render-props/viewport](https://npm.io/package/@render-props/viewport.md) ^0.3.0

## 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.18 (latest) — 2019-03-20
- 0.1.17 — 2019-02-25
- 0.1.16 — 2019-02-25
- 0.1.15 — 2019-01-31
- 0.1.14 — 2019-01-12
- 0.1.13 — 2018-12-29
- 0.1.12 — 2018-09-11
- 0.1.11 — 2018-09-10
- 0.1.10 — 2018-08-21
- 0.1.9 — 2018-08-20
- 0.1.8 — 2018-08-18
- 0.1.7 — 2018-08-18
- 0.1.6 — 2018-08-18
- 0.1.5 — 2018-05-15
- 0.1.4 — 2018-03-26
- … 4 more at https://npm.io/package/@render-props/image-props/versions

## README

# ImageProps
A state container which provides an interface for getting the natural size,
rendered size and orientation from `<img>` elements.

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

## Usage
```js
import ImageProps from '@render-props/image-props'

const ImageWithStats = props => (
  <ImageProps>
    {
      ({
        orientation,
        width,
        height,
        naturalWidth,
        naturalHeight,
        complete,
      }) => (
        <div>
          <img src='some-cat-photo.jpg' ref={hoverRef}/>
          Loaded? {complete};
          Width: {width};
          Height: {height};
        </div>
      )
    }
  </ImageProps>
)
```

____

## Render Props

#### Ref
- `imageRef`
  - This `ref` must be provided to whatever element you are trying to observe the
    the size or orientation of. e.g. `<img ref={imageRef}>`

#### State
- `orientation {landscape|square|portrait}`
  - returns `landscape` when `width > height`, `square` when `width == height`,
    and `portrait` when `width < height`
- `width {number}`
  - the rendered width of the image
- `height {number}`
  - the rendered height of the image
- `naturalWidth {number}`
  - the actual width of the image
- `naturalHeight {number}`
  - the actual height of the image
- `complete {bool}`
  - `true` if the image loaded successfully

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