• Stars
    star
    353
  • Rank 120,322 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A React component for wrangling image loading

react-imageloader

🚨 This project is not maintained! 🚨

We are no longer using this component in our day-to-day work, so unfortunately, we have neglected maintenance of it for quite some time. Among the reasons why we haven't been using this component are:

However, it may still work for you. If you are looking for something like this, but don't want to take on an unmaintained dependency, check out this fork.

See the support matrix below if you are determined to use this.


One of the hardest things to wrangle in the browser is loading. When images and other linked elements appear in the DOM, the browser makes decisions on when to load them that sometimes result in problems for a site and its users, such as FOUC, unexpected load ordering, and degraded performance when many loads are occurring.

This React component can improve the situation by allowing you to display content while waiting for the image to load, as well as by showing alternate content if the image fails to load.

Usage

import React from 'react';
import ImageLoader from 'react-imageloader';

function preloader() {
  return <img src="spinner.gif" />;
}

React.render((
  <ImageLoader
    src="/path/to/image.jpg"
    wrapper={React.createFactory('div')}
    preloader={preloader}>
    Image load failed!
  </ImageLoader>
), document.body);

Props

Name Type Description
className string An optional class name for the wrapper component.
imgProps object An optional object containing props for the underlying img component.
onError function An optional handler for the error event.
onLoad function An optional handler for the load event.
preloader function An optional function that returns a React element to be shown while the image loads.
src string The URL of the image to be loaded.
style object An optional object containing styles for the wrapper component.
wrapper function A function that takes a props argument and returns a React element to be used as the wrapper component. Defaults to React.createFactory('span').

Children

Children passed to ImageLoader will be rendered only if the image fails to load. Children are essentially alternate content to show when the image is missing or unavailable.

For example:

React.createClass({
  // This will only show if "notgonnaload.jpg" doesn't load.
  errorMessage() {
    return (
      <div>
        <h2>Something went wrong!</h2>
        <p>Not gonna load "notgonnaload.jpg". bummer.</p>
      </div>
    );
  },
  render() {
    return (
      <ImageLoader src="notgonnaload.jpg">
        {this.errorMessage()}
      </ImageLoader>
    );
  }
})

Design Decisions (mistakes?)

Since v2.0, loading is done 'off DOM' in a JavaScript Image() (instead of hidden in the DOM via a React <img />), so values passed to the onLoad and onError callbacks will be the browser native values, not React's synthesized values. While this shouldn't be a problem for the vast majority of use cases, it can cause weirdness when browser caching is disabled (i.e., images loading twice, preloaders disappearing before the image is ready).

Supported versions of React

React ImageLoader
<0.13 1.x

=0.13, <15 | 2.x =15 | 3.x

More Repositories

1

django-enumfields

Real Python Enums for Django
Python
145
star
2

gsap-react-plugin

A GSAP plugin for tweening React.js component state.
CoffeeScript
130
star
3

react-google-analytics

Google analytics component
CoffeeScript
111
star
4

django-staticbuilder

Add a build step to your static asset flow.
Python
76
star
5

django-ecstatic

An expansion pack for django.contrib.staticfiles!
Python
70
star
6

django-periodically

Python
39
star
7

reactdi

Dependency injection for ReactJS components.
CoffeeScript
27
star
8

react-pressable

Add onRelease, onReleaseInside, onReleaseOutside, and onPress events to a component
JavaScript
18
star
9

react-controlfacades

Style form controls but use their default behavior
JavaScript
13
star
10

urllite.js

A tiny, tiny URL parser.
JavaScript
11
star
11

react-loadqueueloader

A React component for managing loads with a load queue
CoffeeScript
11
star
12

react-loadermixin

A React mixin for giving components loading behavior
CoffeeScript
10
star
13

bedrock

a highly unopinionated and minimal front-end toolset built in LESS
CSS
7
star
14

django-galleries

The main django-galleries project.
Python
6
star
15

django-modeltools

Enums in your models, template strings for FileField names…
Python
5
star
16

django-mailmate

Define emails with classes and use templates for HTML emails.
Python
5
star
17

react-code39svg.js

Render Code 39 Barcodes as SVGs with React
JavaScript
4
star
18

linter-configs

A repository of config files for all the linters we use
JavaScript
4
star
19

react-qrsvg.js

Render QR codes as SVGs with React
JavaScript
3
star
20

timeout-after.js

Easily add timeouts to any function
JavaScript
3
star
21

cas-maestro

WordPress.org Plugin Mirror
PHP
3
star
22

django-google-search

Django app to show google site search results
Python
3
star
23

queueup.js

A promise-based JavaScript asset loader.
JavaScript
2
star
24

dirtyhex

Hexadecimal Naughtiness
2
star
25

django-combocache

Write-through caching for Django
Python
1
star
26

django-memcachedkeys

Sanitize your keys, please.
Python
1
star
27

disallow-new.js

Don't let people use "new" on your function
JavaScript
1
star
28

drf-url-content-type-override

Python
1
star
29

as-factory.js

Create factory functions from classes!
JavaScript
1
star
30

fabric-envclasses

Set up your fabric environments with a more declarative syntax
Python
1
star