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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fancy-image-loader

v0.0.7

Published

A generic React component to show a placeholder in place of an image while the image is loading and replace the placeholder with the image when the image has loaded.

Readme

fancy-image-loader NPM version

A generic React component to show a placeholder in place of an image while the image is loading and replace the placeholder with the image when the image has loaded.

Features:

  1. Placeholder can be another image or an HTML element
  2. You can style the placeholder/error element
  3. All attributes of tag are supported

Context

Most of the modern websites use images in some form or the other in their content. For example, e- commerce websites commonly have pages showing a list of products with the products’ images.

Whenever you navigate to a web page that has one or more images in it, the browser tries to load those images. And loading an image may take time depending upon the size of the image and the network of the user. So sometimes images can take a lot of time to load. And usually how browsers behave is that until the image has loaded, the browser would have nothing to show. This is generally considered a bad user-experience because the user does not know if something is expected in that content area but as soon as the image loads, it suddenly appears. So it is considered a good practice to show a placeholder until the image has loaded. Facebook takes this practice to another level by showing placeholder for the entire page until the content has loaded.

Getting Started

npm i fancy-image-loader 

or

npm install fancy-image-loader 

Usage - Example 1

import React from 'react';
import {render} from 'react-dom';
import FancyImageLoader from 'fancy-image-loader';

let placeholder = () => {
    return <img src="file/path/loading.gif"/>
}

let error = () => {
    return <img src="file/path/error.png"/>
}

let imageItem = "https://images.alphacoders.com/151/151291.jpg";

render(
  <FancyImageLoader 
        src={item}
        placeholder={placeholder}
        error ={error}
        class="img"
        alt = "Awesome image dude"
        style = {{borderRadius : '9px'}}
        height="200px"
        width="300px"></FancyImageLoader>
, document.getElementById('root'));

Usage - Example 2 (HTML Placeholer)

import React from 'react';
import {render} from 'react-dom';
import FancyImageLoader from 'fancy-image-loader';

let itemHtmlStyle = {
    display: "flex",
    justifyContent: "center",
    height: "100%",
    alignItems: "center",
    textAlign: "center",
    background: "azure"
}

let placeholder = function () {
    return  <img src="http://www.tbaf.org.tw/event/2016safe/imgs/loader1.gif" style={itemStyle}/>;
}

let placeholderHtml = function () {
return <div style={itemHtmlStyle}>
            Loading image please wait
        </div>  
}

let errorHtml = function () {
return <div style={itemHtmlStyle}>
            Sorry image failed
        </div>  
}

let imageItem = "https://images.alphacoders.com/151/151291.jpg";

render(
  <FancyImageLoader 
        src={item}
        placeholder={placeholderHtml}
        error ={errorHtml}
        class="fancy-image"
        alt = "Awesome image dude"
        style = {{borderRadius : '9px'}}></FancyImageLoader>
, document.getElementById('root'));

Props

Name | Required | Type | Description | --------------|----------|----------|-------------- src | Yes | string | Source path of the image to be loaded + displayed
placeholder | Yes | function | A Placeholder function which returns simple react element html/image to be dispayed before image loads/loading error | No | function | An optional error function which returns simple HTML/image to be displayed when image failed to load. If error doesn't provided then placeholder will stay in place. class | No | string | css class property for the image element width | No | string | An optioal width attribute string 100px, 200px etc height | No | string | Height attribute string 100px, 200px etc alt | No | string | Alternative text content style | No | object | Style object containing css stuff for the image component. border | No | string | Standered border styling - 0px solid etc.

Author

Krishcdbry [[email protected]]

Demo

Click here [https://krishcdbry.github.io/fancy-image-loader/demo/]

Licence

MIT @krishcdbry