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

https://github.com/joeshub/react-use-image

React hook to preload an image
https://github.com/joeshub/react-use-image

hook hooks image img preload-images react react-use

Last synced: 7 months ago
JSON representation

React hook to preload an image

Awesome Lists containing this project

README

          

# react-use-image

A react hook for pre-loading images.

## install it

```bash
npm i react-use-image

# or

yarn add react-use-image
```

## use it

```jsx
import useImage from 'react-use-image';

const Example = ({ src }) => {
// use the hook
// pass it an image source url
const { loaded } = useImage(src);

if (!loaded) return null;

return Example;
};
```

## input

Image URL, e.g.

## return values

```js
{
"loaded": false, // image found and loaded
"failed": false, // image not found

// actual size of the image
"dimensions": {
"width": 0, // width of image in pixels
"height": 0 // height of image in pixels
}
}
```

## Docs

- Storybook coming soon

## Authoer

Joe Seifi

## Licence

MIT