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

204
Vistas
react await async calling too soon giving undefined then the right result

I'm using async and await, however the result it calling two sets of times, the first set returns the empty default from the useEffect, and then 2nd time returns the correct data from the call.

This is leading to the data not rendering in the component.

import { Grid } from '@material-ui/core';
import React, { useEffect, useState } from 'react';
import { useEasybase } from 'easybase-react';

export default function Data() {

    const [easybaseData, setEasybaseData] = useState([]);

    const { db } = useEasybase();

    const mounted = async() => {
        const ebData = await db("cars").return().limit(1).all();
        setEasybaseData(ebData);
    };

    useEffect(() => {
        mounted();
    }, []);    

    console.log('easybaseData');

    const ez = easybaseData[0]; 

    const i = ez?.image;
    const n = ez?.name;
    const p = ez?.price;

    console.log(i);

    return (
        <Grid item xs={6} id={"outputs-grid"}>
            <div className="image-result-wrapper">
                <img
                    src={`http://localhost:3000/assets/images/${i}`}
                    className="image-result"
                />
                </div>
                <div className="details-result-wrapper">
                <p className="details-result">{n}</p>
                </div>
                <div className="price-result-wrapper">
                <p className="price-result">{`Evaluation: $${p}`}</p>
            </div>
        </Grid>
    )
}

and the console.log:

enter image description here

What am I missing about this? All 3 data for image, name and price are returning undefined in inspector.

enter image description here

about 4 years ago · Juan Pablo Isaza
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