Last active
November 17, 2018 18:57
-
-
Save sag1v/a319f6c230f7fc29425100c86469475d to your computer and use it in GitHub Desktop.
react integration with other applications article
This file contains 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
class Counter extends Component { | |
state = { count: this.props.initialCount || 0 } | |
updateCount = val => () => { | |
const { onCountUpdate } = this.props; | |
this.setState(state => { | |
const nextCount = state.count + val; | |
return { count: nextCount } | |
}, | |
() => onCountUpdate(this.state.count) | |
); | |
} | |
render() { | |
const { count } = this.state; | |
const { title } = this.props; | |
return ( | |
<div className="counter"> | |
<h3 className="title">{title}</h3> | |
<div className="buttons"> | |
<button onClick={this.updateCount(1)}>+</button> | |
<span className="count"> {count} </span> | |
<button onClick={this.updateCount(-1)}>-</button> | |
</div> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment