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?