State in class component in react js

State in class component in react js

import React, {Component} from "react";

class ClassComponent extends Component{

    constructor(){
        super();
        this.state = {
           data: 1
        }
    }

    updateState(){
        this.setState({
            data: this.state.data + 1
        });

    }

    render(){
        return (
            <>
               <center> {this.state.data}<br/><br/>
                   <button onClick={() => this.updateState()}>Update Stack</button>
               </center>
            </>
        )
    }
}

export default ClassComponent;

Leave a Reply