Qhov no yog vim setState hloov lub xeev thiab ua rau rov ua dua. Qhov no tuaj yeem ua haujlwm kim thiab ua rau nws synchronous yuav ua rau lub browser tsis teb. Yog li lub setState hu yog asynchronous nrog rau batched kom zoo dua UI kev paub thiab kev ua tau zoo.
Vim li cas setState txoj kev yog asynchronous?
Txhawm rau hloov kho lub xeev ntawm ib feem, koj siv txoj hauv kev setState. Txawm li cas los xij nws yog ib qho yooj yim kom tsis nco qab tias cov txheej txheem setState yog asynchronous, ua rau tsis yooj yim rau kev debug teeb meem hauv koj cov cai. Lub setState muaj nuj nqi kuj tsis rov qab cog lus Siv async / tos lossis lwm yam zoo sib xws yuav tsis ua haujlwm.
Can setState ua synchronous?
Nws yuav zoo li txawv tab sis yog setState tuaj yeem ua haujlwm synchronously hauv react.
Vim li cas thiaj ncua sijhawm hauv setState?
piav qhia. Xav txog setState() raws li qhov kev thov es tsis yog ib qho lus txib tam sim los hloov kho cov khoom. Txhawm rau pom qhov ua tau zoo dua, React tuaj yeem ncua nws, thiab tom qab ntawd hloov kho ntau yam hauv ib qho dhau los. React tsis lav tias lub xeev hloov pauv tam sim ntawd.
Puas yog React JS synchronous lossis asynchronous?
Ua ntej tshaj plaws, yog, nws is asynchronous.