How to read the property of the nested object React Redux?

Please help me to get the property of the embedded object React redux:

{
  "id":1
  "name":"Jonh"
  "pets": {
    "namepets": {
      "String":"King-kong"
      "Valid": true
    },
    "age": {
      "String":"11",
      "Valid": true
    }
  }
}

If i write console.log(this.props.user.pets), I see this object in my console, but I write console.log(this.props.user.pets.namepets).

I have this error:

TypeError: Cannot read property 'namepets' of undefined

How do I get this value?

Upvotes: 1

Views: 154

Answers (1)

Blue
Blue

Reputation: 22911

If you're getting this object:

{"id":1,"name":"Jonh","pets":{"namepets": {"String":"King-kong","Valid": true}, "age": {"String":"11","Valid": true}}}

After checking this.props.user.pets, then the full property of this would be:

this.props.user.pets.namepets.pets.namepets

(Not very pretty is it)

Upvotes: 1

Related Questions