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

300
Vistas
How to display a table from an object returned by functional component that calls fastAPI endpoint?

I am building a web app that given some user input, does some math, and outputs the profit per hour of each item that can be created by an inputted building.

Here is an example input:

Physics laboratory 2 1.0 0.01

and output:

{
    Energy research: 821.6746356364301, 
    Mining research: 742.7240922619478, 
    Electronics research: 864.3855853308221
}

I want to display a table using this data, with columns named like Item and Profit Per Hour.

I studied this React Functional Table and others that use .map to display a table. However, when I tried to copy/paste the example and adapt useState to my output example given above, I got errors that each child in the list must have a Key or something to that effect.

I have read lists and keys in React. I feel I should open a new venv and create-react-app to play around with map and keys.

Is this the correct direction to take to display a table like I intend?

Here is an example of my code showing a functional component that takes input from text fields and calls the api endpoint using them to return an object.

I wonder whether the async is potentially causing the key errors as maybe the table is trying to be created before the promise finishes.

const populateTable = async () => {
    try{
        let encodedName = encodeURI(buildingName)
        let targetURI = `http://127.0.0.1:8000/api/calculateProfitPerHourOf{}?buildingName=${encodedName}&buildingLevel=${buildingLevel}&productionModifierPercentage=${productionModifierPercentage}&administrationCostPercentage=${adminCostPercentage}`
        let res = await axios.get(targetURI);
        let arr = res.data
        setResult(arr);
        console.log(arr)
    } catch(e) {
        console.log(e)
    }
}

const HandleClick = () => {
    populateTable();
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I used react-tables to accomplish dynamic row data in a table with fixed columns, not without a lot of help and struggle. I first had to restructure my output data into a nested array so that I would have keys that I could use as accessors, this made things easier to read anyways. See here for an example and help I got from another.

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