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

86
Views
two api response render in table body with react

How can i render two api response dataOne & dataTwo in table body with map? Like dataOne in first two tablecell & data two in 3rd tablecell

let URL1 = "http://api_url/users"
let URL2 = "http://api_url/users-card"

const promise1 = axios.post(URL1, inputValue , {headers: {'Content-Type': 'text/plain'}});
const promise2 = axios.post(URL2, inputValue , {headers: {'Content-Type': 'text/plain'}});

Promise.all([promise1, promise2]).then(function(values) {
  setDataOne(values[0]);
 setDataTwo(values[1]);
});
 <TableContainer>
      <Table>
        <TableHead>
          <TableRow>
            <TableCell>Dessert (100g serving)</TableCell>
            <TableCell align="right">Calories</TableCell>
            <TableCell align="right">Fat&nbsp;(g)</TableCell>
          </TableRow>
        </TableHead>
         <TableBody>

             <TableCell>DataOne</TableCell>
              <TableCell>DataOne</TableCell>
              <TableCell>DataTwo</TableCell>

       </TableBody>
      </Table>
    </TableContainer>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming that you're using effects and state for dataOne and dataTwo, first, declare table cell render function:

const renderCell = (content, index) => <TableCell key={index}>{content}</TableCell>;

And then use map in the component render function:

<TableBody>
    {dataOne.map(renderCell)}
    {dataTwo.map(renderCell)}
</TableBody>

Ideally, you should replace index with the row id. Without the key React would complain that it is unable to track component state. More info about keys and lists: https://reactjs.org/docs/lists-and-keys.html

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!