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

91
Visualizações
Mapping nested data object within an array

I have the following data from JSON that I need to render in the front end of my application:

JSON in Redux Slice

{
    "documentGenerated": [
        {
            "documents": 
                {
                    "documentName": "string",
                    "documentStoreId": {{faker 'random.number'}},
                    "documentTitle": "string"
                }
            ,
            "groupName": "string",
            "groupId": {{faker 'random.number'}}
        }
    ],
}

My console log returns the data correctly from my redux slice which I import into my component, however, when I try to map the data it returns the following error:

Error

TypeError: e.documents.map is not a function at line 63

which corresponds to this line of code in the component:

docGenerated.documents.map((document, documentStoreId) => (

Finally, here is how I am mapping the data within the component:

Component

 const documentGenerated = useSelector(selectDocumentGenerated);

 <Card
                type="default"
                title={(
                  <div>
                    {documentGenerated.map((docGenerated) =>
                      docGenerated.documents.map((document) => (
                        <div>
                          <p key={{ documentStoreId }}>{document.documentName}</p>
                        </div>
                      )),
                    )}
                  </div>
                )}
              />

I'm not sure exactly what I am doing wrong, but I took a look at this example from S/O: React - how to map nested object values? however, I keep running into the same error. I believe that I'm not mapping the documents object correctly within the JSON. Any help in the right direction is greatly appreciated.

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

0

Your code docGenerated.documents.map(...) looks good, it doesn't seem to be the problem.

It might be you're missing the [ ] around documents in your sample redux state slice:

"documents": 
  {
    "documentName": "string",
    "documentStoreId": {{faker 'random.number'}},
    "documentTitle": "string"
  },

If that's the case you can't .map on documents because it's an Object and not an Array.

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