Skip to content

Instantly share code, notes, and snippets.

@bietkul
Created February 14, 2019 17:58
Show Gist options
  • Save bietkul/be752a7635a1191f3532c706430fe402 to your computer and use it in GitHub Desktop.
Save bietkul/be752a7635a1191f3532c706430fe402 to your computer and use it in GitHub Desktop.
A component to use progressive images.
import React from 'react';
import PropTypes from 'prop-types';
import ProgressiveImage from 'react-progressive-image';
const Image = ({
src, alt, placeholderStyle, ...props
}) => (
<ProgressiveImage src={src} placeholder="">
{(currentSrc, loading) => (loading ? (
<div style={{ background: '#040203', ...placeholderStyle }} {...props} />
) : (
<img src={currentSrc} alt={alt} {...props} />
))
}
</ProgressiveImage>
);
Image.propTypes = {
src: PropTypes.string,
alt: PropTypes.string,
placeholderStyle: PropTypes.object,
};
export default Image;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment