Is there a reason that calling setSate()
in a loop would prevent it from updating the state multiple times?
I have a very basic jsbin that highlights th
From the React Docs:
setState() does not immediately mutate this.state but creates a pending state transition. Accessing this.state after calling this method can potentially return the existing value. There is no guarantee of synchronous operation of calls to setState and calls may be batched for performance gains.
Basically, don't call setState
in a loop. What's happening here is exactly what the docs are referring to: this.state
is returning the previous value, as the pending state update has not been applied yet.