Advertisement
Guest User

Untitled

a guest
May 24th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import React from 'react';
  2. import Img from 'gatsby-image';
  3. import { graphql, useStaticQuery } from 'gatsby';
  4.  
  5. const query = graphql`
  6. query {
  7. images: allFile(filter: { extension: { regex: "/jpeg|jpg|png|gif/" } }) {
  8. edges {
  9. node {
  10. extension
  11. relativePath
  12. childImageSharp {
  13. fluid(maxWidth: 560) {
  14. ...GatsbyImageSharpFluid
  15. }
  16. }
  17. }
  18. }
  19. }
  20. }
  21. `;
  22.  
  23. const renderImage = file => {
  24. return <Img fluid={file.node.childImageSharp.fluid} />;
  25. };
  26.  
  27. const Image = props => {
  28. const { images } = useStaticQuery(query);
  29. return renderImage(
  30. images.edges.find(image => image.node.relativePath === props.src),
  31. );
  32. };
  33.  
  34. export default Image;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement