i have object something like this

export const contact = 
  {
    _id: "1",
    first:"John",
    name: {
      first:"John",
      last:"Doe"
    },
    phone:"555",
    email:"[email protected]"
  };

i am reading it like

return (
      <div>
        <h1>List of Contact</h1>
        <h1>{this.props.contact._id}</h1>
      </div>
    )

in this scenario i am getting expected output.

return (
  <div>
    <h1>List of Contact</h1>
    <h1>{this.props.contact.name.first}</h1>
  </div>)

when i read the nested property i am getting error like Uncaught TypeError: Cannot read property 'first' of undefined

how to read these king of nested objects in react

https://github.com/bhavankris/testing1/blob/master/src/pages/contact-list-page.js

please find the github repo

share|improve this question
    
Your post says contact is the variable but you code uses contacts. – The Head Rush 57 mins ago
    
in have connected through redux store and receiving contact as contacts.And i am able to retrieve value of _id – Bhavan Kris 53 mins ago
    
Can you edit your post to correct the typo then? – The Head Rush 52 mins ago
    
have changed it – Bhavan Kris 46 mins ago
    
There might be something more to it than your snippet of code reveals. I have created jsbin.com/firufoc/edit?js,output and it appears to work with your code – user2340824 34 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.