Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Basics (retired) Stateful Components Updating State

incrementScore works fine, but decrementScore does not

decrementScore: function(e) {
     this.setState({
        score: (this.state.score - 1)
      });
  },

  incrementScore: function(e) {
     this.setState({score: (this.state.score + 1)});
  },

  render: function() {
    return (
      <div className="counter">
        <button className="counter-action decrement" onCLick={this.decrementScore}> - </button>
        <div className="counter-score"> {this.state.score} </div>
        <button className="counter-action increment" onClick={this.incrementScore}> + </button>
      </div>
    );
  },  
})

Following the tutorial step by step, however this code above does not decrement the state variable. I've tested with console.log and no logs show - meaning that the decrementScore key isn't being hit for some reason.

1 Answer