I am trying to clear an array, but I'm having trouble.
this.setState({warnErrorTypes:[]})
I'm not sure if I am dealing with a race condition, or what the specific issue is, but I can see that the value of my array is consistently wrong in the case that I need to reset its value to [].
How does one replace an array that contains [1,2] with [] then subsequently [3] where the following are true:
- this.state.warnErrorTypes is an Array which starts out with []
- Based on condition, 2 is pushed in Array
- Based on condition, 1 is pushed in Array.
- Based on condition, 3 is NOT pushed in Array
- Pause. User interacts with UI
- Array is blanked:
this.setState({warnErrorTypes:[]})
- Based on condition, 2 is NOT pushed in Array
- Based on condition, 1 is NOT pushed in Array
- Based on condition, 3 is pushed in Array.
The result of the logic above is always [2,1,3]
, when I expect it to be [3]
.