I am mapping an array in react render. There are multiple DOMs beings rendered.
And each DOM is bound with a click event handler. Which show some details on click.
I want to trigger an auto click on the last element of that array and pass that event to clickHandler.
{
historyData.map((heading, index) => {
return(
<div className="history-node-container" key={index}>
//This is where click handler is being called.
<div className="history-node" onClick={(e) => {this.handleHistoryClick(e)}}>
<span className="history-title">{heading.action}</span>
<input type="hidden" value={heading.comment} className="comment-hidden" />
<input type="hidden" value={heading.by} className="comment-by-hidden" />
<input type="hidden" value={heading.role} className="comment-role-hidden" />
<input type="hidden" value={heading.added_at} className="comment-added-hidden" />
<span className="history-date">{moment(heading.added_at).format("MMMM Do, YYYY")}</span>
</div>
</div>
)
})
}
And clickHandler Code is:
handleHistoryClick(event){
event.stopPropagation();
//Some Code To Display Information Using "event"
}
Now I want to do is if in mapping The element is last one I want to trigger auto click and display it's information accordingly.
How would I achieve that?