I've split a component into a parent and child element. I'm passing data from the parent to the child via states but receiving an Uncaught TypeError: Cannot read property 'imageSource' of null which is odd because I'm following the same process as another element of the application. I've also followed the Components and Props documentation but am still a little stumped.
If I've defined the state, set it, and added it as a property to the child, how come the state is still null?
class Parent extends React.Component {
constructor(){
super();
this.state = {
imageSource: [],
imageTitles: [],
}
}
componentDidMount(){
...
...
// grabbing stuff from Dropbox API
...
...
.then(function(){
that.setState({
imageSource: sources,
imageTitles: titles,
});
});
render(){
return(
<Child imageSource={this.state.imageSource} imageTitles=
{this.state.imageTitles} />
);
}
}
class Child extends React.Component{
render(){
if(!this.state.imageSource.length)
return null;
let titles = this.state.imageTitles.map((el, i) => <p>{el}</p>)
let images = this.state.imageSource.map((el, i) =>
<div className="imageContainer">
<img key={i} className='images' src={el}/>
<div className="imageTitle">{titles[i]}</div>
</div>
)
return (
<div className="ChildWrapper">
{images}
</div>
);
}
}