Is setState really executed asynchronously?

time elapsed before and after I tested with console.time and console.timeEnd before and after setState

console.time("aaa")
this.setState({
    samePageCharts: samePageCharts,
    contentData: contentData,
    activeIndex: activeIndex,
    entityName: data.data.entityName,
    haveNextPage: !data.data.samePageCharts.lastPage
})
console.timeEnd("aaa") //aaa: 870.766845703125ms
The

console prints 800cm. Why? If it is asynchronous, shouldn"t the time be very short?

after rubbing Zhihu, we found that there are Synchronize updates and asynchronous updates in setState.
the event handling process controlled by React setState will not update this.state.state by Synchronize!
in cases outside the control of React, setState updates this.state.state on Synchronize!
the specific link is here

Mar.09,2021

my understanding is that setState does not guarantee Synchronize, that is, sometimes it is asynchronous, sometimes it is Synchronize. It seems that most of the code triggered by user actions is Synchronize.


must be asynchronous.
want Synchronize to execute:

setState({/*..*/}, () => {/* then do something */})
Menu