Peb puas tuaj yeem siv REF hauv kev ua haujlwm?
Peb puas tuaj yeem siv REF hauv kev ua haujlwm?

Video: Peb puas tuaj yeem siv REF hauv kev ua haujlwm?

Video: Peb puas tuaj yeem siv REF hauv kev ua haujlwm?
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Kaum ib hlis
Anonim

Koj yuav tsis siv tus ref attribute rau cov khoom siv ua haujlwm vim lawv tsis muaj piv txwv. Koj ua tau , txawm li cas los xij, siv tus ref attribute nyob rau hauv lub render muaj nuj nqi ntawm a haumxeeb tivthaiv . Koj tuaj yeem siv Ref nuv uas muaj txij li thaum v16.

Yog li ntawd, dab tsi yog txoj hauv kev los tsim kom muaj ref hauv react?

Koj ua tau tsim ref los ntawm kev hu Teb . createRef() thiab txuas a Teb element rau nws siv lub ref attribute ntawm lub caij. Peb tuaj yeem "xa mus" rau ntawm lub pob ref tsim hauv render txoj kev nrog rau kev nkag mus rau tam sim no tus cwj pwm ntawm cov ref.

Ib sab saum toj no, kev siv REF IN react yog dab tsi? Refs yog ib txoj haujlwm muab los ntawm Teb nkag mus rau DOM lub ntsiab lus thiab cov Teb yam uas koj yuav tau tsim ntawm koj tus kheej. Lawv yog siv nyob rau hauv cov ntaub ntawv uas peb xav hloov tus nqi ntawm ib tug me nyuam tivthaiv, tsis ua siv ntawm cov khoom siv thiab tag nrho.

Hauv qhov no, dab tsi yog createRef?

tsimRef () tau txais DOM keeb kwm raws li nws cov khoom tam sim no. Thaum cov ref attribute yog siv rau ntawm cov kev cai hauv chav kawm ntawv, cov khoom ref tau txais qhov piv txwv ntawm cov khoom siv raws li nws qhov tam sim no. Koj yuav tsis siv tus cwj pwm ref ntawm cov khoom ua haujlwm vim tias lawv tsis muaj qhov xwm txheej.

React createRef ua dab tsi?

Tsim Refs - Siv Teb . tsimRef () thiab muab lawv rau Teb cov ntsiab lus ntawm ref attribute. Qhov tseem ceeb, koj muab cov Ref rov qab los ntawm Teb . tsimRef () mus rau ib qho khoom vaj khoom tsev, thaum ib qho khoom tsim tau tsim (aka, hauv cov khoom siv tus tsim). Li no, tus Ref ua tau raug xa mus thoob plaws hauv cov khoom.

Pom zoo: