Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React component cant recognize prop

So i am trying to pass an array of objects from the main App.js file to another smaller component through props but for some reason inside the smaller component file it fails to recognize the prop

smaller_component

error

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It can’t recognize because of the way you’re using the bracket. The syntax that you’re using supposed to be JS injected into JSX so you’d need to wrap your props.items inside a JSX. Without it, JS will interpret it as if you’re trying to initialize an object with key prop and throw an error that a comma is expected instead of a period. If you just want call prop.items like what you’re trying to achieve, there’s no need to wrap it inside the bracket and parenthesis at all and you just need to call return prop.items.map(...)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading