React·100 questions

Why can setState in a loop/multiple times behave unexpectedly?

Answer
Updates are batched.
The value may be outdated.
Use functional updates.
Combine sequential changes into one setState.
For complex scenarios, prefer reducer.
Was this answer helpful?

More questions in this topic

Related questions from other topics