Created
February 14, 2019 17:58
-
-
Save bietkul/be752a7635a1191f3532c706430fe402 to your computer and use it in GitHub Desktop.
A component to use progressive images.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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