Skip to content

Instantly share code, notes, and snippets.

@sag1v
Last active November 17, 2018 18:57
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 sag1v/a319f6c230f7fc29425100c86469475d to your computer and use it in GitHub Desktop.
Save sag1v/a319f6c230f7fc29425100c86469475d to your computer and use it in GitHub Desktop.
react integration with other applications article
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