我试图弄清楚如何使用 graphql 查询将图库图像映射到 Gatsby 中的灯箱组件中。我想我需要设置images = to the childimage sharp array,但我不知道如何构建它,不断出现undefined错误。任何指示将不胜感激。如果需要更多信息,请告诉我。
import React from "react"
import { graphql, Link } from "gatsby"
import Image from "gatsby-image"
import ImageGallery from 'react-image-gallery';
const ComponentName = ({ data }) => {
const {id, galleryImage} = data.home
console.log('data is', data)
const images = [];
return (
<Layout>
<section className="template">
<ImageGallery items={images} />;
</section>
</Layout>
)
}
export const query = graphql`
query GetSingleHome($slug: String) {
home: strapiHomes(slug: { eq: $slug }) {
galleryImage {
formats {
large {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
id
}
}
small {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
id
}
}
}
}
MainImage {
childImageSharp {
fluid {
...GatsbyImageSharpFluid
}
}
}
}
}
`
export default ComponentName
这是画廊组件,以防有帮助
手掌心
相关分类