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

@souvik1991/react-lazy-load-image

v1.0.5

Published

React Lazy Load Image using React Hook plug-in with placeholder image option when in Viewport

Downloads

11

Readme

Lazy Load Image Component using React Hook

Lazy Load any Image using this easy to use React Component. It uses React Hooks out of the box, takes care of component unmount. It prevents the state variable update once the React Component is unmounted.

It's fast, easy on the browser, works in IE8+, 7KB minified. It uses the debounce function by default.

It automatically detects the container which is scrollable and binds scroll event with it.

build status dependency status

Installation

Lazy Load Image Component using React Hook requires React 16.13 or later.

npm install @souvik1991/react-lazy-load-image --save

Live Demo

Usage

import React from 'react';
import LazyLoadImage from "@souvik1991/react-lazy-load-image";

const DemoComponent = () => {
    const mediaUrl = 'https://apod.nasa.gov/apod/image/2010/IMG_7493Colour.jpg';
    return (
        <LazyLoadImage
            className="media"
            alt="post pic"
            placeholder={require('../../static/images/gray.svg')}
            src={mediaUrl}
            onError={() => {
                console.log('Unable to load the image')
            }}
            onContentLoaded={() => {
                console.log('I am loaded');
            }}
            onContentVisible={() => {
                console.log('I am visible');
            }}
        ></LazyLoadImage>
    )
}

Props

placeholder

Type: String Required: Yes

The placeholder is a required props for the plug-in to work. This accept the placeholder image source which will be disaplayed until the image appear in view port. It will also be displayed until the image is loaded.

src

Type: String Required: Yes

The src is a required props for the plug-in to work. This accept the original source of the image which will be loaded once the image is in view port.

alt

Type: String Default: Lazy loaded image

The required alt attribute specifies an alternate text for an image, if the image cannot be displayed. The alt attribute provides alternative information for an image if a user for some reason cannot view it (because of slow connection, an error in the src attribute, or if the user uses a screen reader).

height

Type: String|Number

This is used to set the elements height even when it has no content.

width

Type: String|Number

This is used to set the elements width even when it has no content.

onError

Type Function

A callback function which will be called if it's fails to load the Image.

onContentVisible

Type Function

A callback function to execute when the content appears on the screen.

onContentLoaded

Type Function

A callback function to execute when the content is loaded.

debounceDelay

Type Number Default: 500

The debounce is managed by an internal function that prevents performance issues from continuous firing of scroll events. Using a debounce will set a small timeout when the user scrolls and will keep debouncing until the user stops. The default is 500 milliseconds.