Created
          June 22, 2020 18:02 
        
      - 
      
- 
        Save stephenhmarsh/d71af1ad70e4bfc4557abc66f97bcd38 to your computer and use it in GitHub Desktop. 
    image template example.jsx
  
        
  
    
      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 "./ResponsiveImage.scss"; | |
| class ResponsiveImage extends React.Component { | |
| render() { | |
| const responsiveImage = this.props.photo; | |
| const baseURL = responsiveImage.fields.image.fields.file.url; | |
| const caption = responsiveImage.fields.caption; | |
| return ( | |
| <figure className="responsive-image" key={`${responsiveImage.sys.id}`}> | |
| <img | |
| src={`${baseURL}?w=768&q=80`} | |
| srcSet={`${baseURL}?w=768&q=90 768w, | |
| ${baseURL}?w=992&q=90 992w, | |
| ${baseURL}?w=1200&q=90 1200w, | |
| ${baseURL}?w=1536&q=90 1536w, | |
| ${baseURL}?w=1984&q=90 1984w, | |
| ${baseURL}?w=2400&q=90 2400w, | |
| ${baseURL}?w=2880&q=90 2880w`} | |
| sizes="(orientation: landscape) 66vw, 100vw" | |
| alt={caption && `${caption}`} | |
| width={`${responsiveImage.fields.image.fields.file.details.image.width}`} | |
| height={`${responsiveImage.fields.image.fields.file.details.image.height}`} | |
| ></img> | |
| {caption && <figcaption>{`${caption}`}</figcaption>} | |
| </figure> | |
| ); | |
| } | |
| } | |
| export default ResponsiveImage; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment