Skip to content

Instantly share code, notes, and snippets.

@sachdeva-shrey
Last active February 15, 2020 10:21
Show Gist options
  • Save sachdeva-shrey/150ef2a65ce4f5ddf11d3280d99cd844 to your computer and use it in GitHub Desktop.
Save sachdeva-shrey/150ef2a65ce4f5ddf11d3280d99cd844 to your computer and use it in GitHub Desktop.
Lazy Image Loading
import React from "react"
import { StaticQuery, graphql } from "gatsby"
import Img from "gatsby-image"
const Image = props => (
<StaticQuery
query={graphql`
query {
images: allFile {
edges {
node {
relativePath
name
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
}
}
`}
render={ data => {
return (
<div>
<Img
alt={props.alt}
fluid={image.node.childImageSharp.fluid}
/>
</div>
)
}}
/>
)
export default Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment