Created
June 7, 2018 05:37
-
-
Save adithyamaheshb/a2a52a5a90e1fb6e556f9a4a981b839d to your computer and use it in GitHub Desktop.
Increment/Decrement Counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
clicks: 0, | |
show: true | |
}; | |
this.IncrementItem = this.IncrementItem.bind(this); | |
this.DecrementItem = this.DecrementItem.bind(this); | |
this.ToggleClick = this.ToggleClick.bind(this); | |
} | |
IncrementItem() { | |
this.setState({ clicks: this.state.clicks + 1 }); | |
} | |
DecrementItem() { | |
this.setState({ clicks: this.state.clicks - 1 }); | |
} | |
ToggleClick() { | |
this.setState({ show: !this.state.show }); | |
} | |
render() { | |
return ( | |
<div> | |
<button onClick={this.IncrementItem}>Increment</button> | |
<button onClick={this.DecrementItem}>Decrement</button> | |
<button onClick={this.ToggleClick}> | |
{ this.state.show ? 'Hide number' : 'Show number' } | |
</button> | |
{ this.state.show ? <h2>{this.state.clicks}</h2> : '' } | |
</div> | |
); | |
} | |
} | |
export default App; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment