The first point says to use useReducer() when the next state depends on the previous one - he uses a counter as an example, where the next state is one more than the previous state. The point @clarity89 is making is that the useState() setter function provides a format that gives you access to the previous value in a way that gives you a predictable state transition, so useReducer() is not necessary in this case. You can read the documentation here, but basically the form is (using the counter example):
So basically the first point is invalid, because useReducer() is not necessary to provide a predictable state transition when the next value depends on the previous value.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why?
What you mean?
Explain
The first point says to use useReducer() when the next state depends on the previous one - he uses a counter as an example, where the next state is one more than the previous state. The point @clarity89 is making is that the useState() setter function provides a format that gives you access to the previous value in a way that gives you a predictable state transition, so useReducer() is not necessary in this case. You can read the documentation here, but basically the form is (using the counter example):
setState(prevCounterValue => prevCounterValue + 1)So basically the first point is invalid, because useReducer() is not necessary to provide a predictable state transition when the next value depends on the previous value.