Skip to content

Instantly share code, notes, and snippets.

@udittyagi
Created October 29, 2019 09:21
Show Gist options
  • Save udittyagi/fb8788e83dd12e6f6af135033bfff4fc to your computer and use it in GitHub Desktop.
Save udittyagi/fb8788e83dd12e6f6af135033bfff4fc to your computer and use it in GitHub Desktop.
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