Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

345
Visualizações
Rendering json data in react js error: 'TypeError: Cannot read properties of undefined (reading 'item')'

So I am trying to render some data from a json file in react js, but when I try to run it, it always show an error that it cannot read the parent of a certain data from the json because it's undefined even though I am sure that I put it right.

Json file:

{
    "item": [
        {
            "name": "item"
        }
    ]
}

Code:

const main = ({ backEndData }) => {
  return (
    <div className='main'>
        {
            backEndData.items.item.forEach(product => {
                return (
                    <p>{product.name}</p>
                )
            })
        }
    </div>
  )
}

Error:

enter image description here

I am getting the json file from my backend server btw

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I advise you to read about the difference between map and foreach (forEach never return smth). Try displaying items in the console (they are not defined). I can assume that your code will look like this:

backEndData.item.map(product => 
  <p>{product.name}</p>
);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda