Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/FormidableLabs/react-progressive-image

React component for progressive image loading
https://github.com/FormidableLabs/react-progressive-image

Last synced: about 1 month ago
JSON representation

React component for progressive image loading

Awesome Lists containing this project

README

        

# React Progressive Image

[![Maintenance Status][maintenance-image]](#maintenance-status)

[`react-progressive-image`](https://www.npmjs.com/package/react-progressive-image) React component for progressive image loading

### Install

```bash
$ yarn add react-progressive-image
```

The UMD build is also available on [unpkg](https://unpkg.com):

```html

```

If you use the UMD build you can find the library on `window.ReactProgressiveImage`.

### Examples

#### Simple

```jsx

{src => an image}

```

#### With Delay

```jsx

{src => an image}

```

#### With loading argument

```jsx

{(src, loading) => (
an image
)}

```

#### With srcSet

```jsx

{(src, _loading, srcSetData) => (
an image
)}

```

#### Component As Placeholder

If you want to use a component, such as a loading spinner, as a placeholder, you can make use of the `loading` argument in the render callback. It will be true while the main image is loading and false once it has fully loaded. Keep in mind that the `placeholder` props is `required`, so you will need to explicitly declare an empty string as it's value if you plan on using a component in the render callback.

```jsx
const dominantImageColor = '#86356B';
const placeholder = (


);

{(src, loading) => {
return loading ? placeholder : an image;
}}
;
```

#### Progressive Enhancement and No JavaScript

Since this component relies on JavaScript to replace the placeholder src with the full image src, you should use a fallback image if your application supports environments that do not have JavaScript enabled or is progressively enhanced.

You can do this by adding the fallback image inside of a `` tag in the render callback you provide as the `ProgressiveImage` component's child.

```jsx

{src => {
return (







);
}}

```

### Props

| Name | Type | Required | Description |
| ----------- | -------------------------------------- | -------- | ----------------------------------------------- |
| children | `function` | `true` | returns `src`, `loading`, and `srcSetData` |
| delay | `number` | `false` | time in milliseconds before src image is loaded |
| onError | `function` | `false` | returns error event |
| placeholder | `string` | `true` | the src of the placeholder image |
| src | `string` | `true` | the src of the main image |
| srcSetData | `{srcSet: "string", sizes: "string" }` | `false` | srcset and sizes to be applied to the image |

## Maintenance Status

**Archived:** This project is no longer maintained by Formidable. We are no longer responding to issues or pull requests unless they relate to security concerns. We encourage interested developers to fork this project and make it their own!

[maintenance-image]: https://img.shields.io/badge/maintenance-archived-red.svg