Search code examples
reactjsreact-dom

i dont know why click event is not firing.can anyone help me please


enter image description here can anyone solve thisenter image description here


Solution

  • I checked your code and I fixed the problems:

    import React, { Component } from 'react';
    
    export default class Classcompo extends Component {
      constructor(props) {
        super(props);
        this.state = {
          message: 'welcome visitors',
        };
      }
      changeMessage() {
        this.setState({
          message: 'ok',
        });
      }
      render() {
        return (
          <div>
            <h1>{this.state.message}</h1>
            <button onClick={() => this.changeMessage()}>CLICK</button>
          </div>
        );
      }
    }