In my application I have a component state that may be updated in multiple ways:
A user may perform a certain action which would update the state. My backend my send a message via update that would update the state.
Also, the state update involves adding an object to the previous state, so it cannot just overwrite the previous state.
My worry is that if the websocket update and the user initiated update happen at the same time, the state update from one of the events may not occur before the second event is processed. Therefor, whichever event happens second might have stale data.
I just don’t know enough about how React handles state updates in this type of situation to know whether or not I should actually be worried about this. And I’m not really sure exactly where to start looking to find an answer on this.
SO, I guess my question is, given the fact that I’m making state updates based on a websocket message and also a user action, is there any situation where I get a state inconsistency? Or where one of the updates is updating the state based on stale data? If so, how can I fix this? (Preferably without having to install any additional tools like redux)
submitted by /u/SryNot
[link] [comments]