Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

386
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda