Qhov txawv ntawm createElement thiab cloneElement yog dab tsi?
Qhov txawv ntawm createElement thiab cloneElement yog dab tsi?

Video: Qhov txawv ntawm createElement thiab cloneElement yog dab tsi?

Video: Qhov txawv ntawm createElement thiab cloneElement yog dab tsi?
Video: Qhov Txawv Ntawm Lus Hmoob Thiab Lus Mab Mawb 2024, Kaum ib hlis
Anonim

Qhov txawv ntawm createElement thiab cloneElement yog dab tsi ? JSX tau hloov mus rau tsimElement thiab React siv nws los ua React Elements. cloneElement yog siv los ua ib feem ntawm kev thov kom clone ib feem thiab hla cov khoom tshiab.

Tom qab ntawd, dab tsi cuam tshuam cloneElement ua?

Cov Teb . cloneElement () muaj nuj nqi xa rov qab ib daim qauv ntawm ib qho kev teev tseg. Cov khoom siv ntxiv thiab cov menyuam yaus ua tau yuav kis tau rau hauv kev ua haujlwm. Koj yuav siv txoj haujlwm no thaum niam txiv xav tau ntxiv lossis hloov kho cov khoom siv ntawm nws cov menyuam.

Dab tsi yog qhov txawv ntawm PureComponent thiab tivthaiv? Cheebtsam thiab PureComponent muaj ib Qhov txawv PureComponent yog raws nraim tib yam li Cheebtsam tshwj tsis yog tias nws tuav txoj kev yuav tsumComponentUpdate rau koj. Thaum cov khoom siv lossis lub xeev hloov pauv, PureComponent yuav ua ib tug ntiav kev sib piv ntawm ob qho tib si props thiab xeev.

Tsis tas li ntawd, createElement rov qab yog dab tsi?

tsimElement () Tsim thiab rov qab los ib new Teb lub ntsiab ntawm hom muab. Hom kev sib cav ua tau yog ib lub npe tag (xws li 'div' lossis 'span'), a Teb yam khoom siv (chav kawm lossis ib txoj haujlwm), lossis a Teb fragment yam. Code sau nrog JSX yuav hloov mus siv Teb . Saib Teb Yog tsis muaj JSX los kawm ntxiv.

Thaum twg koj yuav tsum siv Docomponentupdate?

Yuav tsumComponentUpdate tso cai rau peb hais tias: tsuas yog hloov kho yog tias cov khoom koj mob siab txog kev hloov pauv. Tab sis nco ntsoov tias nws tuaj yeem ua rau muaj teeb meem loj yog tias koj teeb tsa thiab tsis nco qab nws, vim tias koj qhov React tivthaiv yuav tsis hloov tshiab ib txwm. Yog li siv ceev faj. Feem ntau Siv Case: Tswj raws nraim thaum koj cov khoom yuav rov ua dua.

Pom zoo: