Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!