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

198
Views
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
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!