bonham000 / fcc-react-tests-module

The original freeCodeCamp React/Redux alpha curriculum.
http://hysterical-amusement.surge.sh/
BSD 3-Clause "New" or "Revised" License
77 stars 38 forks source link

React Lesson 45: setting state based on previous state #232

Closed carpben closed 6 years ago

carpben commented 7 years ago
  1. The Facebook Github React Documentation teaches that when change a property in state, based on the previous state, you should use, you should pass setState a funciton. It could look like this:
    handleClick() {
        this.setState( (prevState) => ({
            counter: prevState.counter+1// change code here
        }) );
    }
  2. In the Results component in this lesson there is a constructor. When I use Create-React-App with this code I receive a warning - "Useless constructor".
bonham000 commented 7 years ago

Yeah, this is probably a more technically correct way of performing a state update like this. Also a good opportunity to introduce some of this more nuanced behavior surrounding setState. Thanks for bringing this up.

I'll leave this open to you or anyone else who wants to work on a PR to update this challenge to reflect this!

bonham000 commented 6 years ago

Going to close this in the interest of migrating the curriculum into FCC.