There is a component that, when downloaded, downloads a json object from randomuser.me

The error occurs when the component is rendered due to the fact that it is supposedly not an object at all, the error itself looks like this

undefined is not an object (evalueting "users.map") 

further render method

enter image description here

the object itself looks like this

enter image description here

I understand that after the setState method, the render method should be called automatically, made an alert to check the state, and I was told

[object Object]

but I don’t understand why after the next render call it doesn’t work, thank you so much for the answer, happy new year!

    1 answer 1

    In the const { users } = this.state.users you are trying to find data under the users key in this.state.users object, that is, you are working with some similar structure:

     { this: { state: { users: { users: [...] } } } } 

    although, judging by the componentDidMount method, you need to access the results key and work with it already:

     const { results } = this.state.users 

    I would recommend that you read about the destructuring of objects, well, and about the debugging of the application (the easiest way is console.log, but this is a bad practice, it is better to master debugger and breakpoint right away)