Skip to content
Advertisement

TypeError: this.state.data.map in reactjs

JavaScript

Hii All , I know this question is asked many times but I cant figure it out I’am getting the error. I have checked for all the questions similar to this but haven’t found specific solution if I use another link i.e, “https://jsonplaceholder.typicode.com/users” this one the code works fine .

Advertisement

Answer

The returned data from https://reqres.in/api/users?page=2 is not an array, but an object with a data property containing what you are looking for (an array). The result of the request is :

JavaScript

So you cannot use map function, which is from the Array prototype, on the result of your request. You must access the data property first :

JavaScript

You could also assign json.data to the state.data to avoid the ugly .data.data :

JavaScript
Advertisement