counter--application v1.0.2
We're going to start with a super simple counter.
Out of the box, it doesn't have a lot going on.
Getting the Basic Component Wired Up We'll start with a constructor method that sets the component state.
constructor(props) { super(props); this.state = { count: 0, }; } We'll use that state in the component.
render() { const { count } = this.state;
return (
increment() { this.setState({ count: this.state.count + 1 }); }
decrement() { this.setState({ count: this.state.count - 1 }); }
reset() { this.setState({ count: 0 }); } We'll add those methods to the buttons.
Increment Decrement Reset We need to bind those event listeners because everything is terrible.
constructor(props) { super(props); this.state = { count: 3, };
this.increment = this.increment.bind(this); this.decrement = this.decrement.bind(this); this.reset = this.reset.bind(this); }