Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

counter app in react class based component

import React, { Component } from 'react'

export default class CounterAppClass extends Component {

    constructor(props) {
        super();
        this.state = {
            count: 0
        }
    }

    handleIncrease() {
        this.setState({
            count: this.state.count + 1
        })
    }

    render() {
        return (
            <div className='card'>
                <div className="card-body">
                    <h3 className='text-center mb-2'>Class based Component Counter</h3>
                    <h5>Count is: {this.state.count}</h5>
                    <button className='btn btn-primary w-100 mt-3' onClick={this.handleIncrease.bind(this)}>Increase</button>
                </div>
            </div>
        )
    }
}
 
PREVIOUS NEXT
Tagged: #counter #app #react #class #based #component
ADD COMMENT
Topic
Name
9+9 =