image.js 977 B

1234567891011121314151617181920212223242526272829303132
  1. import React from "react"
  2. import { useStaticQuery, graphql } from "gatsby"
  3. import Img from "gatsby-image"
  4. /*
  5. * This component is built using `gatsby-image` to automatically serve optimized
  6. * images with lazy loading and reduced file sizes. The image is loaded using a
  7. * `useStaticQuery`, which allows us to load the image from directly within this
  8. * component, rather than having to pass the image data down from pages.
  9. *
  10. * For more information, see the docs:
  11. * - `gatsby-image`: https://gatsby.dev/gatsby-image
  12. * - `useStaticQuery`: https://www.gatsbyjs.org/docs/use-static-query/
  13. */
  14. const Image = () => {
  15. const data = useStaticQuery(graphql`
  16. query {
  17. placeholderImage: file(relativePath: { eq: "gatsby-astronaut.png" }) {
  18. childImageSharp {
  19. fluid(maxWidth: 300) {
  20. ...GatsbyImageSharpFluid
  21. }
  22. }
  23. }
  24. }
  25. `)
  26. return <Img fluid={data.placeholderImage.childImageSharp.fluid} />
  27. }
  28. export default Image