5 ms·
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
by caxco93 4y 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 https://beta.reactjs.org/reference/react/useState#setstate)
- chadlavi 4y agoThis is also a much easier to read way of doing it. For others' context, it's something like this: setFoo((f) => f + 1);