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

301
Visualizações
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 Respostas
Responde à pergunta

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 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