title: TypeError: this is undefined - React JS, Javascript
body: <p>I am trying to implement a simple react component which change name on clicking. I am getting the error <code>Error - TypeError: this is undefined</code> while loading my page which has below react component. The error seems to be in the <code>setState</code> line.</p>
  
  <pre><code>class Layer5 extends React.Component {
    constructor(props) {
      super(props);
  
      this.state = {buttonstate: false};
  
    }
  
    componentDidMount() {
  
    }
  
    componentWillUnmount() {
  
    }
  
    handleClick(e) {
      e.preventDefault();
  
      this.setState({buttonstate: !this.state.buttonstate});      
    }
  
    render() {
      var icon = this.state.buttonstate ? 'images/image1.png' : 'images/image2.jpg';
  
      return (
        &lt;div className="layer5"&gt;
          &lt;a href="#" onClick={this.handleClick}&gt;&lt;img src={icon} &gt;&lt;/img&gt;&lt;/a&gt;
        &lt;/div&gt;
      );
    }
  }
  </code></pre>