rich-text icon indicating copy to clipboard operation
rich-text copied to clipboard

[rich-text-react-renderer] Are there any working examples using GatsbyJS?

Open daydream05 opened this issue 6 years ago • 5 comments
trafficstars

daydream05 avatar Apr 30 '19 16:04 daydream05

Query to export...

export const PageQuery = graphql`
  query {
    contentfulPage {
      title
      slug
      richText {
        json
      }
    }
  }
`;

Your page component...

const MyPage = ({data}) => {
  return <>
    {/* Stuff before */}
    {documentToReactComponents(data.contentfulPage.richText.json, /* your options */)}
    {/* Stuff after */}
  </>
}

Basically, use the renderer like you would in any React app and data comes in the shape you query it from the GraphQL endpoint data object. The important note is you want to pass the json field returned from the query as shown above.

This assumes you are using the Gatsby Contentful source plugin.

mgmolisani avatar Apr 30 '19 17:04 mgmolisani

I have a private sandbox for gatsby/RT integration that I can share: https://codesandbox.io/s/5x2ym34k7n

But that's a good point and we'll improve our existing docs on this topic

sbezludny avatar May 02 '19 12:05 sbezludny

@sbezludny The sandbox has an error. It's not working. TypeError: node.data.target.sys.contentType is undefined. Are you guys working on something?

Praneeth-Pike avatar Jun 21 '19 11:06 Praneeth-Pike

I'm seeing the same issue as above. Anyone got an example of querying a contentful rich text field with an embedded entry?

joeweale avatar Aug 02 '19 12:08 joeweale

So the issue I was having is gatsby caching. Needed to run a gatsby clean before develop in order to get the full object property tree.

Might be worth including this in the documentation

joeweale avatar Aug 05 '19 08:08 joeweale