Hacker News new | ask | show | jobs
by caxco93 1191 days 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)
1 comments

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

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

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