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

229
Visualizações
Multidimensional Array returns Cannot read properties of undefined (reading 'map')

When I am working on localhost or even with the build, everything works perfectly, but when the site is deployed I get this error: Cannot read properties of undefined (reading 'map'). I do not understand why. The site is developed with React and Redux.

{questionsAndAnswers.map((q, index) => 
   <div key={q.id} className={"votre-question-card"} onClick={() => history.push(`/question/${q.id}`)}>
      <h3>Votre question {index + 1}</h3>
      <p>{dayjs(q.date).format("DD/MM/YYYY")}</p>

      {q.reponses.map((r)=> {
         if (r.state == 0) return <p className={"votre-question-card-message"}>1 nouveau message</p>;
         else return null;
         }
      )}
   </div>
)}

When I debug it, the first loop of the second map {q.reponses.map((r, index) => works, but the second loop one creates the bug Cannot read properties of undefined (reading 'map')

QuestionsAndAnswers returns a multidimensional array (containing Objects, and an array : reponses, what I am trying to return)

Array (5)
  0 Object
    content: ""
    date: "2022-02-17 14:41:29"
    dateClosed: "0000-00-00 00:00:00"
    id: "10"
    idUser: "3499"
    listReponses: [] (0)
    reponses: Array (2)
       0 {id: "16", idQuestion: "10", idCareManager: "0", date: "2022-02-18 12:10:50", state: "1", …}
       1 {id: "6", idQuestion: "10", idCareManager: "2", date: "2021-12-01 11:44:10", state: "1", …}

  1 {id: "11", idUser: "3499", date: "2022-02-21 10:54:06", dateClosed: "0000-00-00 00:00:00", state: "0", …}
  2 {id: "12", idUser: "3499", date: "2022-02-23 16:07:37", dateClosed: "0000-00-00 00:00:00", state: "0", …}
  3 {id: "13", idUser: "3499", date: "2022-02-23 16:44:48", dateClosed: "0000-00-00 00:00:00", state: "0", …}

The mystery for me is that it works on localhost and the build, but not on production, with the same browser. Can somebody help me ??

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

0

The above error is occuring in q.reponses.map. To solve this you have to add below code:

    {q.reponses && q.reponses.map((r) => {
      if (r.state == 0)
        return (
          <p className={'votre-question-card-message'}>
            1 nouveau message
          </p>
        );
      else return null;
    })}
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