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

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

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