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

147
Visualizações
React and fetch allocate table columns and rows

I am new to React and I am using Ant Design as a framework. So far I have made good progress on my project, getting the backend up and running and working on the frontend with many components working correcly. Happy with the progress until this point!

Now I am trying to generate a table getting the data from my API. I have managed to retrieve the data using inside my class component using:

render(){       
const workpack = fetch(process.env.REACT_APP_API_URL+'work_package')
              .then((response) => response.json())
              .then((data) => console.log(data));

I have inspected the site and it returns correctly the API data as:

0: {work_package_ID: 1, work_package_name: 'Package1'}
length: 1
[[Prototype]]: Array(0)

My issue comes when I try to allocate the table column headers (keys) or the rows (values).

If I use Object.keys(workpack) or Object.values(workpack) to create new constants extracting the data, I cannot obtain the desired values and I think it is because fetch has put a "0" as a key in front of the array.

In the end, I am looking for a generalized procedure to generate the "dataSource" array and "columns" arrays (as shown in the documentation from Ant) without having to copy manually all the information from my tables.

Any hint or clear reference? I have been researching for a while, but I don't seem to land a good source.

Thanks a lot!

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

0

Try Object.keys(workpack[0]) or Object.values(workpack[0])

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