3.0.0 • Published 5 years ago

react-async-image v3.0.0

Weekly downloads
91
License
MIT
Repository
github
Last release
5 years ago

react-async-image

ReactJS 'img' tag rendering with loading styles, async decoding and error fallback.

Note: required React v16.8+

Install

npm i -S react-async-image

Usage

import Image from 'react-async-image';
const images = ['./images/picture1.jpg', './images/picture2.png'];

<div className="wrapper">
  {images.map((src, index) => (
    <div key={index} style={{ width: 100, height: 100 }}>
      <Image
        src={src}
        className="image"
        placeholder={<div className="placeholder">oops</div>}
      />
    </div>
  ))}
</div>
.image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 1;
  transition: opacity .5s;
}

.image-loading {
  opacity: 0;
  transition: none;
}

Props

namedescriptiontypedefault
srcThe image URLstring
alt?An alternative text description of the imagestring
decoding?Decoding hint to the browserauto | sync | asyncasync
loading?auto | eager | lazylazy
className?CSS class of the imagestringasync-image
placeholder?A fallback element if the image could be loadedReact.ReactNode | string