Created
October 29, 2019 09:21
-
-
Save udittyagi/fb8788e83dd12e6f6af135033bfff4fc to your computer and use it in GitHub Desktop.
This file contains 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'; | |
const Image = ({ src, | |
srcSet, | |
alt, | |
fallbackSrc, | |
isLazy, | |
onClick, | |
style }) => ( | |
<img | |
src={isLazy ? fallbackSrc : src} | |
alt={alt} | |
className={isLazy ? 'lazy' : ''} | |
srcSet={isLazy ? '' : srcSet} | |
data-srcset={srcSet} | |
data-src={src} | |
style={style} | |
onClick={onClick} | |
/> | |
) | |
Image.propTypes = { | |
src: PropTypes.string.isRequired, | |
alt: PropTypes.string.isRequired, | |
} | |
Image.defaultProps = { | |
onClick: () => { }, | |
isLazy: false | |
} | |
export default Image; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment