JSX tau muab tso ua ke li cas?
JSX tau muab tso ua ke li cas?

Video: JSX tau muab tso ua ke li cas?

Video: JSX tau muab tso ua ke li cas?
Video: udt cAGC nLcd$iwgS)JKn[IfUd mbMB-Jmp_FxI_dEce cORJ OJH yKyb YftH&WMM,kjOR Yjo%dEz;APO[vXg_hCV XMNI S 2024, Kaum ib hlis
Anonim

Yog li, yog tias cov ntaub ntawv JavaScript muaj JSX , uas cov ntaub ntawv yuav tsum tau transpiled. Qhov ntawd txhais tau tias ua ntej cov ntaub ntawv tau mus rau lub web browser, a JSX compiler yuav txhais ib yam JSX nyob rau hauv tsis tu ncua JavaScript. JSX tsim React "cov ntsiab lus". Lub ntsiab lus React tsuas yog ib qho khoom sawv cev ntawm DOM node.

Kuj nug, JSX parsed li cas?

JSX tsuas yog siv HTML-zoo li syntax thiab hloov nws mus rau hauv nested React. Qhov tseem ceeb muaj 3 yam uas peb yuav tsum paub thaum twg kev txheeb xyuas a JSX code: Lub npe / tivthaiv ntawm React element. Cov khoom siv ntawm React element.

Tsis tas li ntawd, JSX yog dab tsi? JSX yog XML/HTML-zoo li syntax siv los ntawm Teb uas txuas ECMAScript kom XML/HTML-zoo li ntawv tuaj yeem ua ke nrog JavaScript/ Teb code. Tsis zoo li yav dhau los, es tsis txhob muab JavaScript rau hauv HTML, JSX tso cai rau peb tso HTML rau hauv JavaScript.

Ntxiv mus, JSX ua haujlwm li cas?

JSX yog cov kauj ruam ua ntej uas ntxiv XML syntax rau JavaScript. Koj tuaj yeem siv tau tiag tiag Teb tsis muaj JSX tab sis JSX ua Teb ntau elegant. Ib yam li XML, JSX tag muaj lub npe tag, yam ntxwv, thiab me nyuam. Yog hais tias tus nqi attribute yog nyob rau hauv quotes, tus nqi yog ib txoj hlua.

React puas yuav tsum tau muab tso ua ke?

Muab tso ua ke hauv Teb Thaum tsim lub sijhawm JSX yog muab tso ua ke mus rau qhov tseem ceeb JavaScript code. Txij li ob qho tib si Babel thiab TypeScript txhawb JSX txij li lub sijhawm ntev, React ua Tsis txhob hais qhov version ntawm Babel lossis TypeScript koj yuav tsum siv hauv koj qhov project. Cov sau ua ke txheej txheem nws tus kheej yog heev yooj yim thiab yooj yim to taub.

Pom zoo: