Skip to content

Instantly share code, notes, and snippets.

@lukejoliat
Created April 15, 2019 15:06
Show Gist options
  • Save lukejoliat/cf17cae5e4e2f3a54f5edca7d1a15e5e to your computer and use it in GitHub Desktop.
Save lukejoliat/cf17cae5e4e2f3a54f5edca7d1a15e5e to your computer and use it in GitHub Desktop.
import React from "react"
import { StaticQuery, graphql } from "gatsby"
import Img from "gatsby-image"
/*
* This component is built using `gatsby-image` to automatically serve optimized
* images with lazy loading and reduced file sizes. The image is loaded using a
* `StaticQuery`, which allows us to load the image from directly within this
* component, rather than having to pass the image data down from pages.
*
* For more information, see the docs:
* - `gatsby-image`: https://gatsby.dev/gatsby-image
* - `StaticQuery`: https://gatsby.dev/staticquery
*/
const Image = () => (
<StaticQuery
query={graphql`
query {
placeholderImage: file(relativePath: { eq: "gatsby-astronaut.png" }) {
childImageSharp {
fluid(maxWidth: 300) {
...GatsbyImageSharpFluid
}
}
}
}
`}
render={data => <Img fluid={data.placeholderImage.childImageSharp.fluid} />}
/>
)
export default Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment