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

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

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