Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { Component } from 'react';
- class Counter extends Component {
- render() {
- const { counter } = this.props;
- return (
- <div className='counter'>
- <button
- className='btn btn-primary'
- onClick={() => this.props.onIncrement(counter)}
- >
- Increment
- </button>
- <button
- className='btn btn-secondary'
- onClick={() => this.props.onDecrement(counter)}
- >
- Decrement
- </button>
- <span className={this.getValueClass()}>
- {this.formatCount()}
- </span>
- </div>
- );
- }
- formatCount = () => {
- const { value } = this.props.counter;
- return value === 0 ? 'zero' : value;
- };
- getValueClass = () => {
- const { value } = this.props.counter;
- let cssClass = 'badge badge-';
- cssClass += value === 0 ? 'warning' : 'dark';
- return cssClass;
- };
- }
- export default Counter;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement