Skip to content
Advertisement

I am getting read property map of undefined.I have tried everything but nothing worked

I have tried many solutions given on StackOverflow as well as on other platforms but nothing worked. I am new to ReactJs and I am unable to understand what is wrong in this code that I am getting this error.

JavaScript

}

Advertisement

Answer

The Promise from axios does not resolve instantly and it is very likely that the render function was called before

JavaScript

was executed, meaning that this.state.blogs is undefined.

You could either add

JavaScript

in the constructor or check whether this.state.blogs is undefined before calling its map function:

JavaScript
Advertisement