Dab tsi yog useeffect cleanup function?

Cov txheej txheem:

Dab tsi yog useeffect cleanup function?
Dab tsi yog useeffect cleanup function?

Video: Dab tsi yog useeffect cleanup function?

Video: Dab tsi yog useeffect cleanup function?
Video: Full React Tutorial #24 - useEffect Cleanup 2024, Hlis ntuj nqeg
Anonim

Kev cuam tshuam kev ua haujlwm React ua qhov kev ntxuav thaum cov khoom tsis sib haum Tus useEffect nuv yog tsim nyob rau hauv ib txoj kev uas yog tias peb rov qab ua haujlwm nyob rau hauv txoj kev, nws tau raug tua thaum lub tivthaiv tshem tawm. … Hauv React 17, qhov useEffect cleanup functions tau ncua mus txog rau theem kev cog lus tiav.

Kev ntxuav hauv React yog dab tsi?

React ua qhov cleanup thaum lub tivthaiv unmounts. … Qhov no yog vim li cas React kuj ntxuav cov teebmeem los ntawm qhov kev ua dhau los ua ntej yuav khiav cov teebmeem tom ntej.

Dab tsi yog kev phiv tshuaj ntxuav hauv React?

3. Kev ntxuav ntawm cov khoom siv lossis lub xeev hloov. Thaum nyob rau hauv lub tsev noj mov daim ntawv thov qhov kev phiv tshuaj ntxuav tshwm sim thaum cov khoom tsis sib haum, tej zaum yuav muaj rooj plaub thaum koj xav rho tawm qhov kev thov ntawm cov khoom hloov kho Qhov ntawd yuav tshwm sim, piv txwv li, thaum qhov tshwm sim tshwm sim nyob ntawm qhov khoom siv.

Effect siv rau dab tsi?

1. useEffect yog rau side-effects. Lub luag haujlwm React tivthaiv siv cov khoom siv thiab / lossis lub xeev los laij cov zis. Yog tias cov khoom siv ua haujlwm ua rau kev suav uas tsis yog lub hom phiaj tus nqi tso tawm, ces cov kev suav no raug hu ua kev cuam tshuam.

Thaum twg yuav tsum sivEffect?

3 Teb. Lub tswv yim siv useEffect nuv yog txhawm rau ua cov lej uas xav tau tshwm sim thaum lub sijhawm ua haujlwm ntawm cov khoom siv tsis yogntawm cov neeg siv kev sib cuam tshuam lossis DOM cov xwm txheej.

Pom zoo: