Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-lazy-load-image-observer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-lazy-load-image-observer

The LazyLoadImage component allows you to lazy load images, or background-images, and set the observed element.

  • 0.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

react-lazy-load-image

The LazyLoadImage component allows you to lazy load images, or background-images, and set the observed element.

Install

yarn add react-lazy-load-image

or

npm install react-lazy-load-image

Import

import LazyLoadImage from 'react-lazy-load-image'

About

The wrapperRef declares the element you want to observer to trigger the image loading.

Use imageRef if you want to load an image to an <img> element.

Use backgroundRef if you want to load an image to an element's background-image.

If you omit wrapperRef, the observed elem will be imageRef. You can omit backgroundRef as well.

Props

propdesc
imageSrcsrc of the image, string
classAddedname of class added to the observed element once the image has loaded, default is loaded

In order to animate, you'll have to add css in in regards to the .loaded class.

Something like

opacity: 0;
transition: opacity 400ms ease-in-out;

&.loaded {
  opacity: 1;
}

OR if using a wrapperRef, then

opacity: 0;
transition: opacity 400ms ease-in-out;

& .loaded {
  opacity: 1;
}

^^ notice the space in & .loaded, versus &.loaded

Examples

<LazyLoadImage imageSrc={src}>
  {({ wrapperRef, imageRef, backgroundRef }) => (
    <span ref={wrapperRef}>
      <img ref={imageRef} />
      <span ref={backgroundRef} />
    </span>
  )}
</LazyLoadImage>
<LazyLoadImage imageSrc={src}>{({ imageRef }) => <img ref={imageRef} />}</LazyLoadImage>
<LazyLoadImage imageSrc={src}>
  {({ backgroundRef }) => (
    <div>
      <div ref={backgroundRef} />
    </div>
  )}
</LazyLoadImage>

Keywords

FAQs

Package last updated on 30 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc