index.jsx 527 B

1234567891011121314151617
  1. import PropTypes from "prop-types";
  2. import ReactImgix from "react-imgix";
  3. const Imgix = ({ src,alt="",className="lazyload", ...props}) => {
  4. if (props.width!=null){
  5. let devicePixelRatio=window.devicePixelRatio;
  6. if (devicePixelRatio<1)devicePixelRatio=1;
  7. props.width=Math.ceil(props.width/devicePixelRatio);
  8. }
  9. return (
  10. <ReactImgix className={className} src={src} alt={alt} {...props}></ReactImgix>
  11. )
  12. }
  13. Imgix.propTypes = {
  14. src:PropTypes.string.isRequired
  15. }
  16. export default Imgix