Total Item Count display with item add button

0 9
import React, { Component } from ‘react’;
class Counter extends Component {
    state ={
        count:0,
    };
    styles = {
        fontSize:10,
        fontWeight:”bold”
    };
    handleIncrement = ()=> {
        //console.log(“Increment Clicked”,this);
        this.setState({count: this.state.count +1})
    };
    render() {
        return(
        <div>
            <span className={this.getBadgeClasses()}>{this.formatCount()}</span>
            <button onClick={this.handleIncrement} className=”btn btn-primary”> increament</button>
        </div>
        );
    }
    getBadgeClasses() {
        let classes = “badge m-2 “;
        classes += this.state.count === 0 ? “badge-warning” : “badge-primary”;
        return classes;
    }
    formatCount(){
        return this.state.count === 0? ‘zero’: this.state.count;
    }
}
export default Counter;

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More