I am trying to generate click event for button. I have put button in variable to map different buttons for service but click event is not working. Its giving "Cannot read property 'addCompnay' of undefined.". Can someone help me with this.
class Sidebar extends React.Component {
constructor(props) {
super(props);
this.state = {
allServices:[],
}
this.addCompnay = this.addCompnay.bind(this);
}
addCompnay() {
alert("asd");
}
render() {
var sidebarpagedata = this.state.allServices.companies.map(function(sidebarpagedata, index){
<Button type="button" className="default pull-right" onClick={this.addCompnay} >Apply Now</Button>
})
return (
{sidebarpagedata}
);
}