Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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 Respuestas
Responde la pregunta

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda