4 Teb. Thaum lub sij hawm VirtualDOM Reconciliation yog tias muaj ib qho kev tivthaiv tab sis yuav tsis muaj lawm, cov khoom raug txiav txim siab unmounted thiab muab sij hawm los ntxuav (ntawm componentWillUnmount). Thaum rhuav ib tsob ntoo, cov qub DOM nodes raug puas tsuaj. Component instances txais componentWillUnmount.
Vim li cas kuv cov khoom thiaj tsis cuam tshuam React?
Cov ntsiab lus raug tshem tawm thaum niam txiv tivthaiv tsis tau ua ntxiv lawm lossis cov niam txiv tivthaiv ua qhov hloov tshiab uas tsis ua qhov piv txwv no. ReactDOM. unmountComponentAtNode tseem yuav ua rau unmount.
Yuav ua li cas koj nres cov khoom los ntawm kev tshem tawm?
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 yog unmounting ib feem?
componentWillUnmount yog qhov kawg ua haujlwm raug hu tam sim ua ntej cov khoom raug tshem tawm ntawm DOM. Nws feem ntau yog siv los ua kom huv si rau ib qho DOM-cov ntsiab lus lossis cov sijhawm ua haujlwm tsim hauv componentWillMount. Ntawm kev noj mov, componentWillUnmount sib haum ua ntej koj tuaj tos koj daim pam noj mov.
Dab tsi ua rau cov khoom tiv thaivWillUnmount?
componentWillUnmount yog invoked tam sim ua ntej ibtivthaiv yog unmounted thiab puas. Ua ib qho kev tu kom tsim nyog hauv txoj kev no, xws li kev siv sijhawm tsis raug cai, tshem tawm cov kev thov hauv lub network, lossis ntxuav txhua qhov kev tso npe uas tau tsim nyob rau hauv componentDidMount.