3.0.0 • Published 6 years ago

react-responsive-img v3.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

React Responsive Image

Preserves aspect ratio space while loading in an image. Can be used with srcset and alt tags. Also can optionally show a loading animation.

Note: To preserve image space, the image will be styled as a block element.

Installation

With Yarn:

yarn add react-responsive-img

Or with npm:

npm install --save react-responsive-img

Usage

Basic usage:

import Img from 'react-responsive-img'

const imageComponent = () => {
	<Img
		src='http://via.placeholder.com/500x1000'
		width={500}
		height={1000}
		alt={this.state.product.title}
		/>
}

With loading animation:

import Img from 'react-responsive-img'
import LoadingAnimation from 'loading-animation'

const imageComponent = () => {
	<Img
		src='http://via.placeholder.com/500x1000'
		width={500}
		height={1000}
		loading={<LoadingAnimation />}
		/>
}

With srcset:

import Img from 'react-responsive-img'
import LoadingAnimation from 'loading-animation'

const imageComponent = () => {
	<Img
		srcSet={`
			http://via.placeholder.com/125x250 125w,
			http://via.placeholder.com/250x500 250w,
		`}
		src='http://via.placeholder.com/500x1000'
		width={500}
		height={1000}
		/>
}
3.0.0

6 years ago

2.0.9

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago