I have a "Single Type" Page in Prismic with some normal content fields like uid
or headline
. It also has slice content with non-repeatable fields.
This is what my query looks like:
export const homeQuery = graphql`
query Home {
prismicHome {
data {
page_title {
text
}
introline {
text
}
hero_headline {
text
}
body {
... on PrismicHomeBodyProjects {
__typename
primary {
client_name {
text
}
}
}
}
}
}
}
`
And in my page I am returning it like this:
const IndexPage = ({ data: { prismicHome } }) => {
return(
<LayoutHome>
<Hero
introline={prismicHome.data.introline.text}
headline={prismicHome.data.hero_headline.text}
/>
</LayoutHome>
)
}
But what I can't find out is how to map over my slice fields (i.e. client_name
) without using the ApolloClient the are using in their docs?
My first naive attempt failed and returns a TypeError: Cannot read property 'data' of undefined
:
const projects = homeQuery.prismicHome.data.body.primary.map(({ client_name }) =>
<div>
<h2>{client_name}</h2>
</div>
)