New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-load-image

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-load-image

A React component for showing placeholder content during image loading

latest
Source
npmnpm
Version
0.1.7
Version published
Weekly downloads
3.1K
-43.76%
Maintainers
1
Weekly downloads
 
Created
Source

react-load-image

This is a fork of https://github.com/hzdg/react-imageloader, however many design changes were made and deprecations fixed so it warranted its own repo/package.

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

Installing

npm install react-load-image

Usage

import React from 'react';
import ImageLoader from 'react-load-image';

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

React.render((
  <ImageLoader
    src="/path/to/image.jpg"
  >
    <img />
    <div>Error!</div>
    <Preloader />
  </ImageLoader>
), document.body);

Props

NameTypeDescription
onErrorfunctionAn optional handler for the [error] event.
onLoadfunctionAn optional handler for the [load] event.
srcstringThe URL of the image to be loaded, will be passed as the src prop to your first child provided. If you want to use it as a background image, make your first child a react component like Name = (props) => <div style={{backgroundImage: props.src}}/> and do
srcSetstringAn optional value for the srcset attribute of the img

Children

The first child of ImageLoader will be rendered when the image is successfully loaded. The src prop will be passed to it.

The second child of ImageLoader will be rendered when the image load fails.

The third child of ImageLoader will be rendered when the image is in the process of loading

Avoiding duplication Example

import React from 'react';
import ImageLoader from 'react-load-image';
import ImageError from './ImageError';
import ImageLoading from './ImageLoading';

const Image = (props) =>
  <ImageLoader {...props}>
    {this.props.children[0]}
    <ImageError />
    <ImageLoader />
  </ImageLoader>

export default Image;
import Image from './Image';

...
<Image style={{width: '50px'}}>
  <img style={{border: none}} />
</Image>
...

Using it as a backgroundImage

import React from 'react';

const BackgroundImage = ({src, style = {}, ...props} = {}) =>
  <div style={Object.assign({backgroundImage: `url(${src})`}, style)} {...props} />

export default BackgroundImage;
  <Image style={{width: '50px'}}>
    <BackgroundImage />
  </Image>

Keywords

react-component

FAQs

Package last updated on 14 Jan 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