-1

How to make it work as an increment button:

import React, { Component } from 'react';
export default class Logon extends Component{
    constructor(props){
        super(props);
        this.state = {
            counter: 0
        }
    }
render(){   
        return(
               <button onClick={() => {this.state.counter = this.state.counter + 1}}> 
                       {this.state.counter}
               </button>
        );
 }
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

2
You need to call the `setState` to set the value of state in React.

<button onClick={() => {this.setState({counter: counter+1})}> 
   {this.state.counter}
</button>

Refer State in React js

Alok Mali
  • 2,821
  • 2
  • 16
  • 32