I have a ReactJS component named as <ImageVoteItem/> . I have a button called 'Add Option'. When I click this button <ImageVoteItem/> should appear. When I click the button again, another <ImageVoteItem/> component should appear.
I have done this using states. But I can only render one <ImageVoteItem/> component. How can I render the same component over and over whenever I click the 'Add Option' button?
My class
class ImageVotePost extends Component {
constructor() {
super();
this.state = {
addOption: false,
}
this.addOption = this.addOption.bind(this);
}
addOption() {
this.setState({
addOption: true,
})
}
render() {
return (
<div className="padding5px margin_bottom10px">
<ImageVoteItem/>
<ImageVoteItem/>
{this.state.addOption ? <ImageVoteItem/> : null}
<div className="image_add_btn border" onClick={this.addOption}>
<div className="width_100 relative_position">
<img src={plus} className="plus_icon"/>
<a className="add_opt_text">Add Option</a>
</div>
<input type="file" id="src" className="filetype2"/>
</div>
</div>
)
}
}