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 cannot read properties of undefined props

my code

my error

my object

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

As seen in the images, react says I cannot access the .title on my object despite the fact that it exists.

When I console log the object after commenting out the JSX it logs the objects meaning it is not an issue with the connection to the database.

Been stuck on this for hours any help is appreciated!

As seen in the images, react says I cannot access the .title on my object despite the fact that it exists.

When I console log the object after commenting out the JSX it logs the objects meaning it is not an issue with the connection to the database.

Been stuck on this for hours any help is appreciated!

>Solution :

Welcome to stackoverflow!
In the future, please copy your code instead of adding images.

It looks like bean is undefined, or maybe it is undefined at one lifecycle of the component.

You can solve it in two ways.
at the beginning of the component, you can add

if(!bean) {
  return null;
}

Or when you access bean do it like this:

{bean?.title}
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