Created
April 26, 2018 17:52
-
-
Save whoisryosuke/6e2bf8a1c511a970a5630609514c31e4 to your computer and use it in GitHub Desktop.
Best practice for importing static images into GatsbyJS to ensure lazyloading/scaling. If image is responsive (like background cover image), use sizes property instead of resolutions in query and <Img /> component. See: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-image
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, { Component } from "react"; | |
import Img from "gatsby-image"; | |
export default class Frontpage extends Component { | |
render() { | |
return ( | |
<div className="Frontpage pt2"> | |
<Img resolutions={this.props.data.PeaceEmoji.resolutions} alt="Peace sign emoji" /> | |
</div> | |
); | |
} | |
}; | |
export const query = graphql` | |
query IndexQuery { | |
PeaceEmoji: imageSharp (id: { regex: "/peace.png/" }) { | |
...emojiImageFields | |
}, | |
} | |
fragment emojiImageFields on ImageSharp { | |
resolutions(width: 54, height: 54) { | |
...GatsbyImageSharpResolutions | |
} | |
} | |
`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment