1.0.9 • Published 5 years ago

react-image-async v1.0.9

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

React Image Async

A render prop component to get an image loading status.

Installation

npm install react-image-async

or

yarn add react-image-async

How it works

This library offers a render prop component that exposes the loading status of one or multiple images. It is useful for error handling and graceful image rendering.

Example (single image):

import React from "react";
import ImageAsync from "react-image-async";

const SRC =
  "https://www.tesla.com/sites/default/files/images/software_update.jpg";
export default () => (
  <ImageAsync src={SRC}>
    {({ loaded, error }) =>
      loaded ? <img src={SRC} /> : <div>Loading...</div>
    }
  </ImageAsync>
);

Example (multiple images):

import React from "react";
import ImageAsync from "react-image-async";

const SRC =
  "https://www.tesla.com/sites/default/files/images/software_update.jpg";
const SRC_2 =
  "https://www.tesla.com/sites/default/files/images/homepage/20180710/ms/homepage-models.jpg?20181117";
export default () => (
  <ImageAsync src={[SRC, SRC_2]}>
    {({ loaded, error }) =>
      loaded ? (
        <React.Fragment>
          <img src={SRC} />
          <img src={SRC_2} />
        </React.Fragment>
      ) : (
        <div>Loading...</div>
      )
    }
  </ImageAsync>
);
1.0.9

5 years ago

1.0.7

5 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago