I have an index of images and titles I am pulling in from Dropbox. I aim to be able to click on a title and load a specific project, but right now I'm simply trying to get to grips with passing the data of a clicked title to the a component.
I've looked at the React tutorial, the documentation & other similar questions on here (& am concerned this will be treated as a duplicate question), but I can't seem to figure out a way of passing the specific title that is clicked. I'm currently getting the error: Cannot read property 'title' of undefined.
I've managed to pull out the specific title via console.log & filled the ProjectTitle component with all of the titles but am stumped at this seemingly simple hurdle.
Thanks
class ProjectTitle extends React.Component{
render() {
return <h1>{this.props.title}</h1>;
}
}
class Index extends React.Component {
constructor(){
super();
this.state = {
imageSource: [],
imageTitles: [],
}
}
componentWillMount(){
…
}
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" onClick={() =>
ProjectTitle.props.title(titles[i].props.children)}>{titles[i]}
</div>
</div>
)
return (
<div className="wrapper">
{images}
<ProjectTitle />
</div>
);
}
}