# use-image

> Custom React Hook for loading images.

Latest version **1.1.4** (published 2025-05-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-image
pnpm add use-image
yarn add use-image
bun add use-image
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2025-05-25 |
| First published | 2019-02-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 195 |
| Maintainers | lavrton |
| Keywords | react, react-hooks, canvas, image |

## Links

- npm: https://www.npmjs.com/package/use-image
- Repository: https://github.com/konvajs/use-image
- Homepage: https://github.com/konvajs/use-image/
- Issues: https://github.com/konvajs/use-image/issues
- npm.io page: https://npm.io/package/use-image

## 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

- 1.1.4 (latest) — 2025-05-25
- 1.1.3 — 2025-05-25
- 1.1.2 — 2025-05-19
- 1.1.1 — 2023-06-21
- 1.1.0 — 2022-09-07
- 1.0.12 — 2022-04-11
- 1.0.11 — 2022-04-11
- 1.0.10 — 2022-02-23
- 1.0.9 — 2022-02-23
- 1.0.8 — 2021-07-15
- 1.0.7 — 2020-12-19
- 1.0.6 — 2020-06-18
- 1.0.5 — 2019-10-04
- 1.0.4 — 2019-06-18
- 1.0.3 — 2019-02-22
- … 4 more at https://npm.io/package/use-image/versions

## README

# useImage React Hook

Custom React Hook for loading images. It loads passed `url` and creates DOM image with such `src`.
Useful for canvas application like `react-konva`.

[Open image demo](https://konvajs.org/docs/react/Images.html)

## Install

```bash
npm install use-image
```


## Usage

```js
import React from 'react';
import { Image } from 'react-konva';
import useImage from 'use-image';

const url = 'https://konvajs.github.io/assets/yoda.jpg';

function SimpleApp() {  
  const [image] = useImage(url);

  // "image" will be DOM image element or undefined

  return (
    <Image image={image} />
  );
}

function ComplexApp() {
  // set crossOrigin of image as second argument, set referrerpolicy as third argument
  const [image, status] = useImage(url, 'anonymous', 'origin');

  // status can be "loading", "loaded" or "failed"

  return (
    <Image image={image} />
  );
}
```



## License

MIT

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