rtivital
10/2/2016 - 11:10 AM

button.js

import React, { Component } from 'react';

export default class Button extends Component {
  constructor(props) {
    super(props);

    this.state = {
      counter: this.props.initialCounter,
      counterCounter: 1,
    };

    this.onClick = this.onClick.bind(this);
    this.onCounterClick = this.onCounterClick.bind(this);
  }

  onClick() {
    this.setState({ counter: this.state.counter + this.state.counterCounter });
  }

  onCounterClick() {
    this.setState({ counterCounter: this.state.counterCounter + 1 });
  }

  render() {
    return (
      <div>
        <button onClick={this.onClick}>{this.state.counter}</button>
        <button onClick={this.onCounterClick}>{this.state.counterCounter}</button>
      </div>
    );
  }
}