Skip to content

Instantly share code, notes, and snippets.

@rtivital
Created October 2, 2016 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rtivital/0702c95dc40215312e77223961c03537 to your computer and use it in GitHub Desktop.
Save rtivital/0702c95dc40215312e77223961c03537 to your computer and use it in GitHub Desktop.
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>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment