Home > Blockchain >  React cannot read properties of undefined props
React cannot read properties of undefined props

Time:02-03

my code

my error

my object

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!

CodePudding user response:

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}
  • Related