Skip to content

Instantly share code, notes, and snippets.

@panduroab
Created January 11, 2017 18:38
Show Gist options
  • Select an option

  • Save panduroab/c137a3b81cb7833743002e7c22e0f594 to your computer and use it in GitHub Desktop.

Select an option

Save panduroab/c137a3b81cb7833743002e7c22e0f594 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
class Display extends Component {
render() {
return <div>{this.props.number}</div>;
}
}
class App extends Component {
constructor() {
super();
this.state = { number: 0 };
}
_increment = () => {
this.setState(prevState => ({
number: prevState.number + 1
}));
}
_decrement = () => {
this.setState(prevState => ({
number: prevState.number - 1
}));
}
render() {
return (
<div>
<h3>Main Container</h3>
<Display number={this.state.number} />
<button onClick={this._increment}>Increment</button>
<button onClick={this._decrement}>Decrement</button>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment