Skip to content
Advertisement

ReactJS – TypeError: Cannot read property ‘name’ of undefined but it is

I have a map function that is supposed to take the data from an list I’ve created and show it to the user but it give me a typerror whenever I try to do that, here’s my map function:

JavaScript

And here’s the piece of code where I attach the items to the array:

JavaScript

I get the following error: “TypeError: Cannot read property ‘name’ of undefined”, I’ve tried manually console logging each element of the list and it is definitely not undefined, why is that happening and how can I fix it?

Advertisement

Answer

You can access the name property directly on item like so:

JavaScript

item is the current element that is being processed in your list.

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