Giter Club home page Giter Club logo

react-external-image's Introduction

react-external-image

Description

A simple and lightweight replacement for the tag with multiple image fallback support.

With React external image, you can provide multiple images which act as a fallback in case the previous image failed to load.

Installation

$ npm install react-external-image --save

Usage

Import react-external-image in your component:

import ExternalImage from 'react-external-image'

Create a component as follows:

const eImg = () => <ExternalImage src="www.example.com/ex.jpg"/>

which translates to:

<img src="www.example.com/ex.jpg">

Fallback Images

You can also add fallback images, in case the image could not be loaded preventing broken <img/>s:

const eImg = () =>
<ExternalImage
src="www.example.com/brokenimage.jpg"
fallbackImages={[
	'www.example.com/fallback1.jpg',
		'www.example.com/fallback2.jpg'
]}
/>

The fallbackImages prop takes an array input and will try to load all the images in the array, starting from the first until an image has been successfully loaded.

Loader

You can also show a spinner/loader till the images are being loaded.

const eImg = () =>
<ExternalImage
src="www.example.com/brokenimage.jpg"
fallbackImages={[
	'www.example.com/fallback1.jpg',
		'www.example.com/fallback2.jpg'
]}
loader={/* any valid react component */}
/>

Props

Parameter Type Description
src string Image's primary src
className string Apply custom classes to the img tag
fallbackImages array Array of fallback URLs in case the primary src is not found.
loader react-component A spinner or any valid react component

License

react-external-image is available under the MIT License.

react-external-image's People

Contributors

anirudhsridhar avatar singhshivam avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.