Skip to content
Advertisement

TypeError: Cannot read property ‘_id’ of undefined ReactJs?

I am trying to get the name of a user based on the user id, using a .map() method. The code that I wrote seems good to me, however, I get the error mentioned in the question title and the page won’t render.

See the image below:

enter image description here

Here’s an image of the error stack:

enter image description here

And here’s the code I have:

JavaScript

So it’s pretty much telling me that the usr[i]._id line is not correct, but as far as I can see nothing is wrong with that code.

Advertisement

Answer

I think you might just want usr and not usr[i]? The map() gives you the individual item from the iterable.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement