Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Gatsby Js, Graph QL - mapping through query, using MarkdownRemark

I am new to Graphql and Gatsby so I am still learning how to access things in graphql.

I am trying to turn my markdown table into html. Currently, my query looks like so:


  const data = useStaticQuery(graphql`
  query {
    allContentfulQuestionAnswer {
      edges {
        node {
          question
          id
          answer {
            answer
            childrenMarkdownRemark {
              html
              id
            }
          }
        }
      }
    }
  }
`)

I am trying to map through the data to get both the questions and the answers. Like so:

    <>
    <h1>FREQUENTLY ASKED QUESTIONS</h1>
    {data.allContentfulQuestionAnswer.edges.map( ({ node, index }) => (
        <div className="repairCost">
        <p>{ node.question }</p>
        <p>{ node.answer.answer }</p>
        </div>
      ))}

I have tried changing { node.answer.answer } to { node.answer.answer.childrenMarkdownRemark } ...etc

When I go into the graphql playground, and I create the query:

  allMarkdownRemark {
    edges {
      node {
        html
      }
    }
  }
}

and map over that. I am able to get the markdown in html form.. however, I need it to be displayed with the question and the answer together.

Currently it looks like: markdown table

Would appreciate all or any help!

Thank you so much!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Use:

<h1>FREQUENTLY ASKED QUESTIONS</h1>
{data.allContentfulQuestionAnswer.edges.map( ({ node, index }) => (
    <div className="repairCost">
    <p>{ node.question }</p>
    <p dangerouslySetInnerHTML={{__html: node.answer.childrenMarkdownRemark.html }} />
    </div>
  ))}

Your loop looks good, however, you are not rendering the answer itself because you need to render HTML, that's why dangerouslySetInnerHTML is useful.

Since the response you are fetching is markdown-like, you may need to use a markdown interpreter in order to display it properly. There are a lot of libraries, but I will base this answer in markdown-to-jsx:

import Markdown from "markdown-to-jsx";

<h1>FREQUENTLY ASKED QUESTIONS</h1>;
{
  data.allContentfulQuestionAnswer.edges.map(({ node, index }) => (
    <div className="repairCost">
      <p>{node.question}</p>
      <Markdown>{node.answer.childrenMarkdownRemark.html}</Markdown>
    </div>
  ));
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!