in the previous two articles, we analyzed the implementation, mounting, and lifecycle processes of React components. In reading the source code, we often see code such as transaction and UpdateQueue , which involves two concepts in React: transactions and update queues. Because we have covered all of these in the previous article, this article explores the transaction mechanism and update queues based on the all-familiar setState method. 1.setState related in the first article Analysis of React Source Code (1): implementation and mounting of components we already know The component prototype declared by class has the setState method: this method passes in two parameters partialState and callBack , the former is the new state value, and the latter is the callback function. updater is defined in the constructor: you can see that updater is passed in by the constructor, so if you find out where new ReactComponent is executed, you can find out what updater is. Taking the custom component ReactCompositeComponent as an example, we found its trail in the _ constructComponentWithoutOwner method: return new Component(publicProps, publicContext, updateQueue); undefined the corresponding parameter updater is actually updateQueue . Let's look at what enqueueSetState is in this.updater.enqueueSetState : The purpose of the getInternalInstanceReadyForUpdate method is to get the current component object and assign it to the internalInstance variable. Next, determine whether the state update queue for the current component object exists, and if so, add the partialState , that is, the new state value, to the queue; if not, create an update queue for the object, and notice that the queue exists as…