ReactComponent.prototype.setState = function(partialState, callback) {// willsetThe State affairs in the queue for this. The updater. EnqueueSetState (this, partialState);if (callback) {
    this.updater.enqueueCallback(this, callback, 'setState'); }};Copy the code

The partialState here produces a new state that is merged with the old state in the form of object.assgine ().

 enqueueSetState: function(publicInstance, PartialState) {/ / get the current component instance var internalInstance = getInternalInstanceReadyForUpdate (publicInstance,'setState'); / / will update the state into an array of var queue. = internalInstance _pendingStateQueue | | (internalInstance. _pendingStateQueue = []); queue.push(partialState); // The component instance to be updated is also placed in a queue enqueueUpdate(internalInstance); }Copy the code

Setstate in native events, setTimeout and setInterval, asynchronous operations such as promise, the state will be an update

When setTimeout is executed, the finally main process block is executed first. When finally is executed, isBatchingUpdates are changed to false. The requestWork would have the same expirationTime === Sync if branch as the native event. If the requestWork would have the same expirationTime === Sync if branch as the native event. The requestWork would have the same expirationTime === Sync if branch as the native event.







22 Before 33, async also returns a Promise object. Yes! That’s return a promise, so promise is an asynchronous method, and in the context, setstate is synchronous