I created a new component in my Reactjs code and have a button there with onClick function. But the onClick function does not work. I tried everything but it still does not work. Any ideas how I can go about solving this?
import React, { Component } from 'react';
import MenuIcon from '@material-ui/icons/Menu';
class HeaderComponent extends React.Component {
constructor(props){
super(props);
this.openMenuBar = this.openMenuBar.bind(this);
}
openMenuBar(){
console.log("open");
}
render(){
return(
<div>
<button onClick={() => { this.openMenuBar()}}>
<MenuIcon/>
</button>
</div>
);
}
}
This component is then called in the app.js
<HeaderComponent/>
UPDATE
Some helful info: Whenever I route it to a path (app/path/xx), then the button is not clickable. Otherwise, is it clickable (if the path is root)
onClick={() => this.clickHandler()}oronClick={() => {return this.clickHandler()}}or evenonClick={this.clickHandler}.openMenuBar.