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

react-image-holder

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-image-holder

React image component with offline placeholder fallbacks

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
9
-43.75%
Maintainers
1
Weekly downloads
 
Created
Source

react-image-holder

Build Status

An <img /> component for React which can render real images as well use an offline placeholder as a fallback if need be.

All placeholders are rendered using holder.js, meaning they will work even when offline. You can even configure the component to always render a placeholder for all its instances.

View demo

Installation

$ npm install react-image-holder

## Examples

All examples assume you have require()-d the component:

var Img = require('react-image-holder');

A real image

var realImage = (
  <Img src="http://animalia-life.com/data_images/cat/cat5.jpg" />
);

Output:

<img src="http://animalia-life.com/data_images/cat/cat5.jpg" />

Additional attributes

var realImage = (
  <Img src="http://animalia-life.com/data_images/cat/cat5.jpg" 
    width="802"
    height="450"
    className="cat-photo" />
);

Output:

<img width="802" height="450" class="cat-photo" src="http://animalia-life.com/data_images/cat/cat5.jpg" />

Use a placeholder instead

var realImage = (
  <Img src="http://animalia-life.com/data_images/cat/cat5.jpg" 
    width="802"
    height="450"
    className="cat-photo" 
    usePlaceholder={true}
    />
);

Output:

<img class="cat-photo" data-src="holder.js/802x450?auto=true&theme=vine" />

Holder.js then processes the above tag and renders a placeholder.

Setting placeholder properties

var placeholderProps = {
  theme: 'blue',
  size: 50,
  auto: false,
};

var realImage = (
  <Img src="http://animalia-life.com/data_images/cat/cat5.jpg" 
    width="802"
    height="450"
    usePlaceholder={true}
    placeholder={placeholderProps}
    />
);

Output:

<img data-src="holder.js/802x450?auto=false&size=50&theme=blue" />

See holder.js property list for all available properties.

Global placeholders

Rather than passing the usePlaceholder property to each instance of the component you can also set this property's default value at the start of your app:

Img.DEFAULT_PROPS.usePlaceholder = true;

Now all subsequent instances of the component will automatically use a placeholder image. And you can still override the setting on per-instance basis!

Building

$ npm install
$ npm run build

Contributing

Contributions are welcome! Please see CONTRIBUTING.md.

License

MIT - see LICENSE.md

Keywords

react

FAQs

Package last updated on 24 Apr 2016

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