Hi Kevin,
Thanks for contributing to the Prismic community.
In fact, with 'gatsby-source-prismic' plugin you still can use Prismic RichText helper in almost the same way, you just need to pass your structured text to the render
attribute such as
<RichText render={slice.primary.section_title.raw}
and use serializeHyperlink={GatsbyLink}
Here is a code snippet that displays a text slice with a structured text field with a link
import React from 'react'
import { RichText } from 'prismic-reactjs'
import GatsbyLink from '../GatsbyLink'
import topIcon from '../../images/top-icon.png'
const TextInfo = ({ slice }) => (
<section className="text-info">
<div className="left-column">
<img src={topIcon} alt="Checkbox icon" />
<RichText
render={slice.primary.left_column_text.raw || []}
serializeHyperlink={GatsbyLink}
/>
</div>
</section>
)
export default TextInfo
And here is how the Gatsby link would look like
import React from 'react'
import { Link } from 'gatsby'
import linkResolver from '../utils/linkResolver'
const GatsbyLink = (type, element, content, children, index) => {
if (element.data.link_type === 'Document') {
return (
<Link to={linkResolver(element.data)} key={element.data.id}>
{content}
</Link>
)
}
return null
}
export default GatsbyLink
Please don't forget to include your link resolver in gatsby-config.js like this
const { prismicRepo, previewPath, releaseID, accessToken } = require('./prismic-configuration')
const linkResolver = require('./src/utils/linkResolver')
const reponame = process.env.PRISMIC_REPO_NAME = process.env.PRISMIC_REPO_NAME || prismicRepo
const prismicReleaseID = process.env.PRISMIC_RELEASE_ID || releaseID || ''
const gastbySourcePrismicConfig = {
resolve: 'gatsby-source-prismic',
options: {
repositoryName: reponame,
accessToken: apiKey,
releaseID: prismicReleaseID,
linkResolver: ({ node, key, value }) => (doc) => linkResolver(doc),
...
},
}
Please let us know if that answers your question,
Fares