1

I have a gatsby website that is using mdx as section instead of pages. I thought this should be simple. I can query all the sections with graphQL

query HomePageQuery {
    allMdx(filter: {fields: {source: {eq: "section"}}}) {
      edges {
        node {
          id
          fields {
            source
          }
          frontmatter {
            graphic
            title
          }
          body
        }
      }
    }
  }

And then render them on the page:

const IndexPage = ({data}) => {

  const sections = data.allMdx && data.allMdx.edges.map((node)=> {
    return <Section {...node} />
  })
  
  return <main>{sections}</main>
}
const Section = ({frontmatter, body}) => {
  console.log(body);
  return (
    <section>
       <h1>{frontmatter.title}</h1>
       {body}
    </section>
  )
}

The problem comes in the <Section /> component, the body is just raw mdx. How do I get the properly formatted content of an MDX node? In the past it seems like I could do this with the <MDXRenderer/> component but that doesnt exist anymore?

https://www.gatsbyjs.com/plugins/gatsby-plugin-mdx/#graphql-mdx-node-structure

The documentation seems to say there should be a automatic property children but this doesn't seem to exist on query thats I do and not ones automaticly done by gatsby.

Am I doing this completely wrong?

vldmrrdjcc
  • 2,082
  • 5
  • 22
  • 41
Ryan
  • 414
  • 1
  • 6
  • 16
  • what version of `gatsby-plugin-mdx` are you using? – Nemoden Oct 19 '22 at 04:52
  • gatsby-plugin-mdx: 4.1.0 - seems like support for the which was specifically built to do this this was dropped in 4? Is there a replacement I'm missing – Ryan Jun 01 '23 at 02:18

0 Answers0