Problem when mapping api with Axios and React,

Asked

Viewed 441 times

0

Good afternoon guys, all right?

I am trying to make an application with React, however, when trying to map a random API, to try to render the data, it fails to return what I am trying to pull.

Would anyone know the problem ?

Ps: had written "lenth" and already corrected for "length", however it did not help at all. :/

inserir a descrição da imagem aqui

Thank you!

  • 3

    can post the code instead of the image

  • 1

    put your returns in console.log(retorno) then boat to debuggar and see if the data is being received correctly

1 answer

2


That method getAll calls a Praomise and the setState has to be called within of then to be chained in the asynchronous nature of that axios.get.

So the code should be:

.then(res => {
    this.setState({list: res.data});
});

You can read more about asynchronous threads here (link).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.