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

380
Views
axios.get always returning a Promise<Pending>

I found different solutions here, but none worked for me. I have this simple code:

const Element = () => {
        async function getEndData() {
            const data = (await getEnd());
            return data;
        }
}

const getEnd = async () => {
    return await axios.get('http://localhost:8080/end').then(res => res.data);
}

And it always return a Promise "pending" with inside a [[PromiseResult]] with the value i need, when i call getEndData(). I tried also to call directly getEnd() removing the then(), returning only the data, but nothing. If i print res.data in console.log, it will return the right value i need.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

this should work:

const Element = () => {
        async function getEndData() {
            const data = await getEnd();
            return data;
        }
}
const getEnd = async () => {
    const response = await axios.get('http://localhost:8080/end');
    return response;
}
about 4 years ago · Juan Pablo Isaza Report

0

I'm not sure you are doing it the right way. You can try this:

const Element = () => {
        return async function getEndData() {
            const data = await getEnd();
            return data;
        }
}

const getEnd = () => {
    return new Promise((resolve, reject) => {
     axios.get('http://localhost:8080/end')
     .then(res => {
      resolve(res.data)
     })
     .catch(err => {
         reject(err);
      })
    }) 
}

Also, What is the use of element function if you are not returning anything.

about 4 years ago · Juan Pablo Isaza Report

0

your getEndData() in returning a promise . add await or then where ever you are receiving the getEndData() response .

// const Element = () => {
    async function getEndData() {
        const data = (await getEnd());
        return data;
    }
// }

const getEnd = async () => {
    return await axios.get('http://localhost:8080/end').then(res => res);
}



async function callEndData(){
    let x = await getEndData()
    console.log(x)
}
callEndData()

since it is returning promise and you are not using await or then it is showing promise pending

why do you need Element() ?

In case you need to call ELement function and also wants the data part of response you can try like this .


const Element = async() => {
    async function getEndData() {
       return await getEnd();
    }

    let fromEndData  = await getEndData()
    return fromEndData 
}

const getEnd = async () => {
    return axios.get('http://localhost:8080/end').then(res => {
       return res.data
    });
}



async function callEndData(){
    let x = await Element()
    console.log(x)
}
callEndData() 

in console.log(x) i am getting the value being passed .

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