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

327
Vistas
Having trouble displaying values retrieved from multiple APIs to Ag-Grid rows (React)

I'm having trouble with this issue for the past couple of days and I've tried somethings but they haven't been working.

I'm trying to display some stock information onto the table. It works fine for one stock however when I try to get multiple stock information and combine it, I get blank values.

Please have a look at the code

useEffect(() => {
        (async () => {
          try {
            let data = []
            data.push(await getAppleData())
            data.push(await getIBMData())
            console.log(data)
            setRowData(await data);
            setLoading(false);
          } catch (err) {
            setError(err);
            setLoading(false);
          }
        })();
      }, []);

Here is what one of the get[name]Data() functions look like:

async function getAppleData() {
        const url = `https://financialmodelingprep.com/api/v3/profile/AAPL?apikey=APIKEY`;
        let res = await fetch(url);
        let data1 = await res.json();
      
        return data1;
      }

In the columns section I have tried these specifications but they aren't working

const columns = [
        { headerName: "Symbol", field: "symbol", 
        valueGetter: function (params) {
          return params.data.symbol;
        },},
        { headerName: "Price", field: "price" },
        { headerName: "Industry", field: "industry" }

      ];

The output I get is this:

Table Output

Also this is the console.log of the rowData

console.log(rowData)

Please can someone help me figure out how to reference the values from the array of objects?

Thank you

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

0

Array.prototype.push will append the entire response to the data array, and looks like the response is an array containing a single object, so data contains two arrays instead of two objects.

To append the objects instead of the arrays, you can use Array.prototype.concat.

useEffect(() => {
  (async () => {
    try {
      let data = [].concat(await getAppleData(), await getIBMData());
      console.log(data);
      setRowData(data);
      setLoading(false);
    } catch (err) {
      setError(err);
      setLoading(false);
    }
  })();
}, []);

You can also use the Spread syntax, as shown below:

useEffect(() => {
  (async () => {
    try {
      let data = [...(await getAppleData()), ...(await getIBMData())];
      console.log(data);
      setRowData(data);
      setLoading(false);
    } catch (err) {
      setError(err);
      setLoading(false);
    }
  })();
}, []);

Also, awaiting data makes no sense, so simply do setRowData(data).

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