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

384
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 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