I have a pretty simple piece of React that loos over an array and outputs tab names. However my click handler no longer works (it worked before when I didn't have the loop).
The difference between this piece and before I had the .map loop is that this new piece has two returns in the render function. One for the outer div element that React requires, then one for the looping over the objects.
Does anyone how I can successfully get the click handler working again please?
Please see my component
class TabMenu extends React.Component {
constructor(props) {
super(props);
this.state = {
};
this.tabMenuList = [
{
title: 'My Account',
section: 'MyAccount'
},
{
title: 'Conference Details',
section: 'MyAccount'
},
{
title: 'My Abstract',
section: 'MyAbstract'
}
];
}
handleClick(e){
e.preventDefault();
console.log('this is the click handler', this);
ReactDOM.render(<Conference />,document.getElementById('content'));
}
render() {
return (
<div>
{this.tabMenuList.map(function(menuItem, index){
return(
<li data={menuItem.section}>
<a onClick={this.handleClick.bind(this)} href={'#'}>
<img src={'assets/img/mail_icon.jpg'} />
<span>{menuItem.title}</span>
</a>
</li>
)
})}
</div>
);
}
}