Problem when mapping api with Axios and React,

0

Good afternoon guys, are you okay?

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

Would anyone know the problem?

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

Thank you!

    
asked by anonymous 27.12.2017 / 21:03

1 answer

2

This getAll method calls a promise and setState must be called within of then to be chained to 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) .

    
28.12.2017 / 07:47