Yuav ua li cas tiv thaiv kev tiv thaiv los ntawm kev tshem tawm?

Cov txheej txheem:

Yuav ua li cas tiv thaiv kev tiv thaiv los ntawm kev tshem tawm?
Yuav ua li cas tiv thaiv kev tiv thaiv los ntawm kev tshem tawm?

Video: Yuav ua li cas tiv thaiv kev tiv thaiv los ntawm kev tshem tawm?

Video: Yuav ua li cas tiv thaiv kev tiv thaiv los ntawm kev tshem tawm?
Video: Yuav tawm ntawm txoj kev txom nyem tau li cas? 2024, Hlis ntuj nqeg
Anonim

Sing react-router koj tuaj yeem tiv thaiv txoj kev hloov pauv tau yooj yim (uas yuav tiv thaiv kev tiv thaiv unmount) los ntawm kev siv Prompt. Koj yuav tsum tau manually hla tus getUserConfirmation prop uas yog ib qho haujlwm. Koj tuaj yeem hloov kho qhov haujlwm no raws li koj nyiam hauv txhua Router (Browser, Memory lossis Hash) los tsim koj cov lus pom zoo kev cai (piv txwv li.

Dab tsi ua rau cov khoom tiv thaiv tsis tuaj yeem?

Cov ntsiab lus raug tshem tawm thaum niam txiv tivthaiv tsis tau rov ua ntxiv lawm lossis tus niam txiv tivthaiv ua qhov hloov tshiab uas tsis ua qhov piv txwv no.

Yuav ua li cas tshem tawm ib feem?

Unmount a React Node

React muaj qib API sab saum toj hu ua unmountComponentAtNode uas tshem tawm ib feem ntawm lub thawv tshwj xeeb. Lub luag haujlwm unmountComponentAtNode siv qhov kev sib cav ua lub thawv los ntawm cov khoom tshwj xeeb yuav tsum raug tshem tawm.

Dab tsi yog unmounting ib feem?

Lub hom phiaj ntawm txoj kev no yog txhawm rau rhuav tshem cov kev mob tshwm sim uas tsim los ntawm kev tivthaiv Thaum cov khoom siv tsis raug tshem tawm, peb siv tsis tau dua. Txhua lub sij hawm ib qho tshiab tau tsim. Tsis tas li yog tias tsis muaj qhov sib txawv hauv virtual dom thiab qhov tseeb dom, react tuaj yeem nres lub sijhawm hloov tshiab ib yam nkaus.

Kuv yuav ua li cas thiaj paub yog tias cov khoom tsis raug tshem tawm?

Tsuas set a _isMounted cuab yeej rau muaj tseeb hauv componentDidMount thiab teeb nws rau qhov tsis tseeb hauv componentWillUnmount, thiab siv qhov hloov pauv no los kuaj xyuas koj cov xwm txheej. Ib qho kev daws teeb meem zoo tshaj plaws yuav yog nrhiav cov chaw uas setState yuav raug hu tom qab ib qho kev cuam tshuam tau unmounted, thiab kho lawv.

Pom zoo: