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

158
Vistas
How to map over 2 Array of object in React and render to Table

how can i map over 2 Array of object in React and render to one Table. what are option for this issue. should i merge these two array into one ? Please check Json Data

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) {
  setDataSetOne(values[0]);
 setDataSetTwo(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>

Json Data 1st

[{
    "name": "adnan hassan",
    "count": 6960
}, {
    "name": "adnan",
    "count": 69666660
}]

2nd Json Data

[{
    "keyword_idea_metrics": {
        "competition": "LOW",
        "avg_monthly_searches": "6600",
        "competition_index": "22",
        "low_top_of_page_bid_micros": "53135896",
        "high_top_of_page_bid_micros": "278963954"
    },
    "keyword_annotations": {
        "concepts": []
    },
    "text": "dubai homes",
    "_text": "text"
}]

Edit: Json Data has been added

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use one object to contain two states like this:

import { useEffect, useState } from 'react';
import axios from 'axios';

const App = () => {
  // use one object to contain two states
  const [data, setData] = useState({ dataOne: '', dataTow: '' });
  // fetch data
  useEffect(() => {
    const fetchData = async () => {
      const dataOne = await axios.post(URL1, inputValue, {
        headers: { 'Content-Type': 'text/plain' },
      });
      const dataTow = await axios.post(URL2, inputValue, {
        headers: { 'Content-Type': 'text/plain' },
      });
      setData({ dataOne, dataTow });
    };
    fetchData();
  }, []);
  // display data
  return (
    <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>{data.dataOne}</TableCell>
          <TableCell>{data.dataTow}</TableCell>
        </TableBody>
      </Table>
    </TableContainer>
  );
};

export default App;

I hope it helpful.

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