npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-imageloader

v3.0.0

Published

A React component for wrangling image loading

Downloads

7,543

Readme

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