Been through a number of iterations trying to figure this one out. Essentially, I'm mapping the _meta.tags, it's generating the correct number of fields (four), but the text isn't populating each field.
When I console.log the data, I can see that the data is there to be plugged in. Not sure if this is something stupid simple I'm missing, or an issue. Everything else on this template is pulling as expected.
import React from 'react'
import { graphql } from 'gatsby'
import { RichText } from 'prismic-reactjs'
import Text from "../components/slicehelper/text"
import Image from "../components/slicehelper/image"
import DoubleImage from "../components/slicehelper/DoubleImage"
const PostSlices = ({ slices }) => {
return slices.map((slice, index) => {
const res = (() => {
switch(slice.type) {
case 'text-block': return (
<div key={ index }>
{ <Text slice={ slice } /> }
</div>
)
case 'image-block': return (
<div key={ index }>
{ <Image slice={ slice } /> }
</div>
)
case 'image-double-block': return (
<div key={ index }>
{ <DoubleImage slice={ slice } /> }
</div>
)
default: return
}
})();
return res;
})
}
const PostBody = ({ blogPost }) => {
return (
<div>
<img src={ blogPost.hero.url } alt={ blogPost.hero.url } />
<h1>{ RichText.render( blogPost.title ) }</h1>
{/* Trying to display the project tags. The four HTML fields are generated but are empty. */}
<div>
{ blogPost._meta.tags.map(({ tagged, index }) => (
<h4 key={index}>{tagged}</h4>
))}
</div>
<p>{ RichText.render( blogPost.intro ) }</p>
<PostSlices slices={ blogPost.body } />
</div>
);
}
export default (props) => {
const doc = props.data.prismic.allProjects.edges.slice(0, 1).pop();
if(!doc) return null;
return(
// console.log(doc.node)
<div>
<PostBody blogPost={ doc.node } />
</div>
)
}
export const query = graphql`
query ($uid: String) {
prismic {
allProjects(uid: $uid) {
edges {
node {
hero
intro
title
_meta {
tags
uid
id
type
}
body {
... on PRISMIC_ProjectBodyTextBlock {
type
label
primary {
text
}
}
... on PRISMIC_ProjectBodyImageBlock {
type
label
primary {
image
}
}
... on PRISMIC_ProjectBodyImageDoubleBlock {
type
label
primary {
first_image
second_image
}
}
}
}
}
}
}
}
`
Been through a number of iterations trying to figure this one out. Essentially, I'm mapping the _meta.tags, it's generating the correct number of fields (four), but the text isn't populating each field.
When I console.log the data, I can see that the data is there to be plugged in. Not sure if this is something stupid simple I'm missing, or an issue. Everything else on this template is pulling as expected.