Last active
October 20, 2019 18:14
-
-
Save simonsisay/4b66b13f4bce8d08ce757050189f7b3a to your computer and use it in GitHub Desktop.
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 from "react"; | |
import Image from "gatsby-image/withIEPolyfill"; | |
import { StaticQuery, graphql } from "gatsby"; | |
const GatsbyImage = ({filename, style, alt}) => { | |
return ( | |
<StaticQuery | |
query={graphql` | |
query { | |
allImageSharp { | |
edges { | |
node { | |
fluid { | |
...GatsbyImageSharpFluid_withWebp | |
} | |
} | |
} | |
} | |
} | |
`} | |
render={data => { | |
const image = data.allImageSharp.edges.find(file => | |
file.node.fluid.src.includes(filename) | |
).node.fluid; | |
if (!image) { | |
return null; | |
} | |
return <Image alt={alt} fluid={image} style={style} />; | |
}} | |
/> | |
); | |
}; | |
export default GatsbyImage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment