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

183
Visualizações
Why is axios not returning correctly

I am trying to replace a fetch with axios. I keep getting undefined in my console log.

async componentDidMount() {        
    console.log('app mounted');

    const tokenString = sessionStorage.getItem("token");
    const token = JSON.parse(tokenString);

    let headers = new Headers({
        "Accept": "application/json",
        "Content-Type": "application/json",
        'Authorization': 'Bearer ' + token.token
    });

    const response = await axios({
        method: 'get',
        url: Config.apiUrl + `/api/Orders/GetAllInvoices`,
        headers: {
            "Accept": "application/json",
            "Content-Type": "application/json",
            'Authorization': 'Bearer ' + token.token }
    });
    console.log(`axios: ${response.json}`)
    this.setState({ invoiceList: response.json });
    
    //const response = await fetch(Config.apiUrl + `/api/Orders/GetAllInvoices`, {
    //    method: "GET",
    //    headers: headers
    //});
    //const json = await response.json();
    //console.log(json);
    //this.setState({ invoiceList: json });
    ...

... the commented out fetch is working. I just now added the .json even though axios should not need it. Neither way works. What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Did you even console.log(response) just to see whats inside of it?

I guess you dont, because response is an object witch has no json key in it. You should use response.data

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