Yuav ua li cas koj xa mus rau ib tug react Cheebtsam?
Yuav ua li cas koj xa mus rau ib tug react Cheebtsam?

Video: Yuav ua li cas koj xa mus rau ib tug react Cheebtsam?

Video: Yuav ua li cas koj xa mus rau ib tug react Cheebtsam?
Video: Overdose Prevention-We Can All Save a Life 2024, Hlis ntuj nqeg
Anonim

Yuav kom tau ib siv rau React Cheebtsam , koj tuaj yeem siv qhov no kom tau txais tam sim no React tivthaiv , los yog koj siv tau ib tug ref kom tau ib siv rau a tiv thaiv koj muaj. Lawv ua haujlwm zoo li no: var MyComponent = Teb . createClass({ handleClick: function() { // Qhia meej meej rau cov ntawv nyeem siv cov raw DOM API.

Ua raws li qhov no hauv kev txiav txim siab, koj yuav ua li cas thiaj li xa mus rau cov ntsiab lus ntawm tus menyuam?

Koj hla tus ref mus rau tus me nyuam tivthaiv raws li ib tug txawv lub npe prop - tiag tiag lub npe lwm yam tshaj li ref (e.g. buttonRef). Cov me nyuam tivthaiv Tom qab ntawd tuaj yeem xa tus prop mus rau DOM node ntawm tus ref tus cwj pwm. Qhov no cia niam txiv hla nws ref mus rau tus me nyuam DOM node los ntawm lub tiv thaiv nyob nruab nrab.

Ib yam li ntawd, refs nyob rau hauv react yog dab tsi thiab vim li cas lawv tseem ceeb? 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 kom hloov tus nqi ntawm ib tug me nyuam tivthaiv, tsis siv cov props thiab tag nrho cov.

Yog li ntawd, dab tsi yog ib qho tshuaj tiv thaiv?

Cheebtsam yog lub tsev blocks ntawm tej Teb app thiab ib txwm Teb app yuav muaj ntau yam ntawm no. Yooj yim muab, a tiv thaiv yog chav kawm JavaScript lossis ua haujlwm uas xaiv tau txais cov khoom siv xws li cov khoom (props) thiab xa rov qab a Teb lub ntsiab lus uas piav qhia yuav ua li cas ib ntu ntawm UI (User Interface) yuav tsum tshwm sim.

Dab tsi yog qhov txawv ntawm ib lub ntsiab lus thiab ib qho khoom siv hauv cov tshuaj tiv thaiv?

React Element - Nws yog ib yam khoom yooj yim uas piav txog DOM ntawm thiab nws cov cwj pwm lossis cov khoom koj tuaj yeem hais. Nws yog cov khoom piav qhia tsis hloov pauv thiab koj tsis tuaj yeem siv txhua txoj hauv kev rau nws. React Component - Nws yog ib txoj haujlwm lossis chav kawm uas lees txais cov tswv yim thiab xa rov qab a React lub ntsiab.

Pom zoo: