top | item 35112610

(no title)

caxco93 | 3 years ago

For the examples regarding Mutating state and Accessing state after changing it I believe it would've been a great chance to teach about "functional updates" on the `set` functions, which can be accomplished by passing a function as an argument instead of the `nextState` value. (ref https://beta.reactjs.org/reference/react/useState#setstate)

discuss

order

chadlavi|3 years ago

This is also a much easier to read way of doing it.

For others' context, it's something like this:

  setFoo((f) => f + 1);