skip to Main Content

I have a React native project

I want to display manufacture’s name (brand name) above the product name like below

<View style={styles.infromationView}>
  <Text>{data.manufacturers.name}</Text>
  <Text>{data.product_description.name}</Text>
</View>

enter image description here

While adding the name, I am getting error as Cannot read property ‘name’ of undefined while getting the manufacturer / brand name table, But I am able to get the same product name from product_description table

enter image description here
enter image description here

Please check below for db structure…

enter image description here

Above table data is working as expected..

But, when I try to get the data from this table, I am getting error

enter image description here

2

Answers


  1. try this

    <Text>{data?.manufacturers?.name}</Text>
    

    for more info: Optional_chaining

    In this, you might be missing values, that’s why it’s showing error!

    Login or Signup to reply.
  2. You can avoid this error by

    <Text>{data?.manufacturers?.name || ''}</Text>
    

    But i think here is the issue is with your API response. I think API response data has no property name "manufacturers".

    Please confirm it by console.log({data}).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search