Skip to content

Instantly share code, notes, and snippets.

@simonsisay
Last active October 20, 2019 18:14
Show Gist options
  • Save simonsisay/4b66b13f4bce8d08ce757050189f7b3a to your computer and use it in GitHub Desktop.
Save simonsisay/4b66b13f4bce8d08ce757050189f7b3a to your computer and use it in GitHub Desktop.
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