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

152
Visualizações
Interact over object of arrays React JS

I have an object like this one:

[
    {
        "periodname": "Test",
        "periodtime": ""
    },
    {
        "periodname": "",
        "periodtime": ""
    }
]

And I want to render a Col for each array inside of it. My React code:

function renderMyPage(props) {

const { myObject } = props

const renderMyPage = () => {
     return [myObject].map((c,i) => {
        return(
            <Col>
              My data here  
            </Col>
          )
       })
    }
}

But I always get only one result, even if I have two or more arrays inside my object.

If I interact again with map or foreach I get the same object. If I use the map function without using "[]" on the object I get an error:

Uncaught TypeError: Cannot read property 'map' of undefined

What I'm doing wrong to get only one result? Tried a lot of other questions around StackOverflow questions but I'm getting the same result.

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

0

As a quick solution try

const renderMyPage = () => {
     return myObject?.map((c,i) => {
        return(
            <Col>
              My data here  
            </Col>
          )
       })
    }
}

or

const renderMyPage = () => {
     if (!myObject) return null;
    
     return myObject.map((c,i) => {
        return(
            <Col>
              My data here  
            </Col>
          )
       })
    }
}
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