I am new with react, i am just wondering what is best solution for receiving value from component created inside another component, that will be anti patern. I have this 2 components - mainComponent have variable with links for images i just created images and saved value of index from table for picture. In canvas i am rendering this image. I just want to save index of clicked image, creating function that will return value from img object will be good solution? or it is antipatern and i should try another way to implement this?
class MainComponent extends React.Component {
constructor(){
super();
this.imageCol = ['link','link']
this.state={
indexOfImage : 0,
};
}
render() {
return (
<div>
<div>
{this.imageCol.map((e,index) => {
return <Image value ={index} source={this.imageCol[index]} key={index} style={this._returnState(index)} />
})}
</div>
<div>
<ReactCanvas image={this.imageCol[this.state.indexOfImage]}/>
</div>
</div>
);
}
}
class Image extends React.Component {
constructor(props){
super(props);
}
render() {
return (
<img value ={this.props.value} onClick={ ()=>{console.log('click'+this.props.value)} } className={this.props.style} src={this.props.source}/>
);
}
}
export default Image;
onClickevent callback prop toImage- deojeff