Found a bug in FCC's React Simple Counter

Found a bug in FCC's React Simple Counter
0.0 0

#1

I found a subtle bug while doing the “React: Write a Simple Counter” challenge.

If you look at the code below you’ll see that I binded this in this.reset to the this .decrement method.
It should be

this.reset = this.reset.bind(this);

The consequence of this error is that clicking the reset button which calls this.reset does not reset the counter and decrements it instead.

However, when I run the tests all the tests are passed and the error is not detected!

I don’t know if I should report this on FCC’s github or just keep it here on the forums (I never reported a bug before). Any advice?

My buggy code



class Counter extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0
    };
    // change code below this line
    this.increment = this.increment.bind(this);
    this.decrement = this.decrement.bind(this);
    this.reset = this.decrement.bind(this);  //Wrong binding
    // change code above this line
  }
  // change code below this line
  increment(){
    const count = this.state.count + 1;
    this.setState({count});
  }
  decrement(){
    const count = this.state.count - 1;
    this.setState({count});
  }
  reset(){
    const count = 0;
    this.setState({count});
  }
  // change code above this line
  render() {
    return (
      <div>
        <button className='inc' onClick={this.increment}>Increment!</button>
        <button className='dec' onClick={this.decrement}>Decrement!</button>
        <button className='reset' onClick={this.reset}>Reset</button>
        <h1>Current Count: {this.state.count}</h1>
      </div>
    );
  }
};

My browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/front-end-libraries/react/write-a-simple-counter

As advised Ariel, I reported the bug on github here.


#2

Bugs should always be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.