Deano
Deano

Reputation: 12200

React unable to render object property

I'm attempting to render the values of props object, When I console.log stats object, chrome dev tools console shows the following object.

Object
_id : "vFgY3YBrLj3Pd7zNA"
active: 652668928
available: 595034112
createdAt: Fri Jan 13 2017 03:56:04 GMT+0400 (GST)
free: 595034112
inactive: 563294208
ownerId: "6Kv93sJdY62iGiCwg"
percent : 86.1

However when I attempt to access .stats property I get undefined

   console.log(this.props.stats._id);

   Uncaught TypeError: Cannot read property '_id' of undefined

Any idea on what I'm going wrong here?

Upvotes: 1

Views: 82

Answers (2)

Deano
Deano

Reputation: 12200

I have noticed that this behavior happens because the object is not fully instantiated

In my case the query to fetch object data was slow, here is an example for fetching last record

Stats.findOne({}, {sort: {DateTime: -1, limit: 1}});

And when I changed it to something like, it worked fine.

Stats.find({}).fetch();

Upvotes: 0

Mayank Shukla
Mayank Shukla

Reputation: 104399

Check this jsfiddle, how to pass props values from parent component and use in child component : https://jsfiddle.net/r7ym0x4r/

Upvotes: 1

Related Questions