我在 Prismic 中有一个“单一类型”页面,其中包含一些正常的内容字段,例如uid
or headline
。它还具有不可重复字段的切片内容。
这是我的查询的样子:
export const homeQuery = graphql`
query Home {
prismicHome {
data {
page_title {
text
}
introline {
text
}
hero_headline {
text
}
body {
... on PrismicHomeBodyProjects {
__typename
primary {
client_name {
text
}
}
}
}
}
}
}
`
在我的页面中,我像这样返回它:
const IndexPage = ({ data: { prismicHome } }) => {
return(
<LayoutHome>
<Hero
introline={prismicHome.data.introline.text}
headline={prismicHome.data.hero_headline.text}
/>
</LayoutHome>
)
}
但是我不知道如何在client_name
不使用他们文档中使用的 ApolloClient 的情况下映射我的切片字段(即)?
我的第一次天真尝试失败并返回TypeError: Cannot read property 'data' of undefined
:
const projects = homeQuery.prismicHome.data.body.primary.map(({ client_name }) =>
<div>
<h2>{client_name}</h2>
</div>
)