I'm passing an object as a prop to a component.
<SomeComponent myData={props.myData}>...</SomeComponent>
In SomeComponent, when I console.log this.props.myData, it is not undefined and contains key/val pairs, as expected.
constructor(props) {
super(props);
console.log(this.props.myData);
…
}
However, when I try to access any one of this object's properties, they are all undefined.
constructor(props) {
super(props);
console.log(this.props.myData.title); // undefined
…
}
Update
The following does output the value, but I'm unclear as to why, since the object is already available without setTimeout.
constructor(props) {
super(props);
setTimeout(() => {
console.log(this.props.fightData.title); // "Work plain near killed us both"
});
…
}
