Today I am facing this issue × TypeError: Cannot read properties of undefined (reading ‘map’) in reactjs

How this problem occurs ?

When I try to run this code it gives me this error: × TypeError: Cannot read properties of undefined (reading 'map').

I don’t know why i have tried possible means didn’t work

Solution 1

There is a prop “products” in your component. That variable has higher priority than the map you have outside, and your .map is using it. I would recommend to rename one of them, to avoid variables with the same name.

Given the error, I would guess that that prop wasn’t passed to the component.

Also, the parameter if the map lambda is “products” too. Change it to “product”, or it will fail

Solution 2

The props products that you’re passing your component (Products) are undefined. The Map method is taking in account the products that you have passed as props not the one that you have created outside the component itself. If you want to map out the products array that you created outside of your components then just change its name as the array has the same name as the props passed. If you want to use the products (from the prop) then make sure that you’re passing the props in the component.

  1. × TypeError: Cannot read properties of undefined

    The props products that you're passing your component (Products) are undefined. The Map method is taking in account the products that you have passed as props not the one that you have created outside the component itself. If you want to map out the products array that you created outside of your components then just change its name as the array has the same name as the props passed. If you want to use the products (from the prop) then make sure that you're passing the props in the component.

  2. TypeError: Cannot read properties of undefined

    The props products that you're passing your component (Products) are undefined. The Map method is taking in account the products that you have passed as props not the one that you have created outside the component itself. If you want to map out the products array that you created outside of your components then just change its name as the array has the same name as the props passed. If you want to use the products (from the prop) then make sure that you're passing the props in the component.

So here is all solution about × TypeError: Cannot read properties of undefined (reading ‘map’)

Also Read, hautelook/AliceBundle is gone in symfony