Chii chinonzi React JS chevanotanga dummies, chii icho, tutorials, kuisirwa, zvinyorwa – maitiro ekuisa uye kushandisa iyo React JS raibhurari kana uchinyora ekutengesa marobhoti. Kazhinji mukushambadzira kwebasa kune nyanzvi dzemakomputa, unogona kuwana chinodiwa chinoti une hunyanzvi muraibhurari yeJavaScript. Hongu, uye vanotarisira ruzivo rweReact kwete chete kubva kune vanogadzira software, asiwo kubva kune vanogadzira mapurogiramu vari kuita mukati mekuvandudza kwesaiti, uye kwete dhizaini yekunze. Iri iraibhurari rudzii, mikana ipi yainopa mubasa, uye anotanga anotanga kujairana kupi? Ngatizvionei munyaya ino.
- JavaScript raibhurari – React: chii ichocho
- Nei raibhurari yeReact ichidikanwa?
- Kuziva kune vanotanga: pfungwa dzekutanga
- Mhoro Nyika!
- Zvinokosha zveJSX system mutauro
- Chii chinonzi JSX?
- Kuumbwa kwemazwi mumutauro wehurongwa
- Detail rendering
- Zvikamu uye Props
- Mhando dzezvikamu: zvinoshanda uye kirasi
- props
- Nyika uye kutenderera kwehupenyu
- Chiitiko chekuongorora
- Conditional kupa zvinhu
- Kuchinja Zvikamu
- Lists uye Keys
- Keys
- Mafomu
- Managed Items
- Kusimuka kwehurumende
- Sei zvakakosha kudzora kusimuka kwehurumende?
- Composition vs Nhaka
- React.js Misimboti
- Kushanda kweraibhurari yeReact.js
- Kushandisa kunoshanda
- Kushanda kwekushandisa kweReact kana uchinyora kutengesa marobhoti muJavaScript
- GitHub uye React.js
- Zvinyorwa
JavaScript raibhurari – React: chii ichocho
React.JS iraibhurari yeanozivikanwa
JavaScript programming language , yakaumbwa neinternet social network Facebook kuitira kuvandudza uye kurerutsa maitiro ekugadzira ekunze shell yemasaiti uye maapplication – iyo interface iyo mushandisi anodyidzana nayo. Chinhu chikuru cheraibhurari zvikamu uye nyika. Chikamu chikamu chedhijitari seti inokonzeresa kutaridzika kwechimwe chikamu chegadziriro iri kugadzirwa.
Cherechedza! Zvikamu zvakadaro zvinogona kuiswa dendere.
Nyika muunganidzwa we data rese nezve ruzivo rwe interface, kusanganisira iyo inomiririra kupa kwayo. Tichishandisa mienzaniso, tichawana zvakadzama uye zvakajeka kuti chii. Mufananidzo uri pazasi unoratidza zvimwe zvezvinhu zvikuru – kutumira kune online social network, chikamu chine ruzivo rwese uye kuratidza mafoto. Chikamu chimwe nechimwe chinosanganisira zvikamu zviduku, izvo zvikamu. Semuenzaniso, chinyorwa chine zvinyorwa, mapikicha, zita remushandisi anoburitsa ruzivo, zvichingodaro. Chikamu chemufananidzo chinosanganisira mapikicha ega ega, uye chikamu chezvese chine ruzivo rupfupi.
Chimwe nechimwe chezvikamu izvi (zvikamu) zvine hurumende. Ndiko kuti, chikamu chine ruzivo rwese chinotaridzika chakasiyana pamidziyo yakasiyana, iyo “yakafanana” chinhu chinoshandura ruvara kana ichidzvanywa uye nhamba inotarisira huwandu hwese hwekuda; bhuku racho, ringapfupisa mashoko acho kana kuti kuaparadzira zvakazara.
Nokudaro, kushanduka kweReact.JS kunoratidzwa – chikamu chekubatanidza chinonyorwa kamwe chete, uye mushure mezvo chinopiwa zvose zvinogoneka.
Nei raibhurari yeReact ichidikanwa?
React.JS ndeimwe yesarudzo dzinogoneka dzekunyora JS kana HTML kodhi mune iri nyore fomati, gadzira makopi ayo uye ita kuti ionekwe. Izvo zvikamu pano zvakanyorwa mumutauro wakasarudzika – JSX, iyo inosanganisira zvinhu zveJavaScript programming mutauro uye yakamisikidzwa HTML markup mutauro.
Kodhi yakanyorwa muJSX yakanyatsojeka. Izvo zvakakoshawo kuti web browser haifanirwe kunzwisisa iyi system mutauro – iyo React.JS kodhi inotamirwa kuJS, iyo chero browser inoona pasina matambudziko. Kuti uite izvi, izvo zvinogadzirwa muraibhurari zvinopfuudzwa kuburikidza neakasarudzika compilers (imwe yeanonyanya kufarirwa nhasi iBabel js), iyo inoshandura macode mumitauro isingazivikanwe hurongwa kuita JavaScript inomiririra.
Pakutanga zvingaite sekuti sisitimu yekushandiswa haina musoro, asi mushure mechinguva iwe unojaira uye unoona kuti sei iyo michina yakagadzirwa nenzira iyoyo. Raibhurari yeJavaScript ine akati wandei mabhenefiti akasimba:
- iyo system programming mutauro iri nyore kuziva kupfuura inozivikanwa JavaScript, uye nekudaro, zvinotora kanoverengeka nguva shoma kutsigira kodhi uye kubvisa zvikanganiso pairi (kukurumidza kwekunyora makodhi matsva uye zvirongwa zvichawedzera zvinoenderana);
- yakanakira uye inoshanda sisitimu yezvinhu zvinoumbwa inovakwa muno – kudzokorora zvikamu zvekodhi iyo inoshandiswa pamatanho akasiyana ekunyora uye muzvirongwa zvakasiyana, uye zvakare shanduko zvichienderana nemamiriro ezvinhu;
- imwe neimwe constituent element iri pasi pemamiriro ayo chete , saka zviri nyore kugadzirisa zvikanganiso mukodhi kana kukanganisa kwakangoerekana kwawanikwa mubasa rayo mukuita; nguva dzisina kururama dzinoyangarara pamusoro: chinhu chinoshanda nemazvo chicharamba chichishanda zvakatsiga mune iyi modhi, kunze kwekunge, chokwadi, chimiro chisiri chikashandiswa maererano nacho.
Nokudaro, tinogona kugumisa kuti raibhurari yeReact.JS inogona kuchengetedza nguva yakawanda, kuita kuti kodhi ive yakanyatsojeka, kuronga kutevedzana muhurongwa hwakarurama, uye kushandisa mabhuroki makuru zvakare. Aya mabhenefiti anoita kuti zvibvire kudzikisa mutengo weiyo nzira yekugadzira mushandisi interface, pamwe nekumhanyisa nguva yeiyi maitiro chaiwo. Kuve nehunyanzvi hwekushandisa JS uye HTML programming mutauro, kudzidza kushandisa system JSX kuri nyore – angori mazuva mashoma kuti ugone.
Cherechedza! Zvine musoro kushandisa raibhurari paunenge uchishanda nemapurojekiti makuru, kana zvichidikanwa kunyora nhamba huru yemapeji ane simba. Nzvimbo yebhizinesi diki haidi kuoma kwakadai.
React JS yakakosha kosi kubva A kusvika Z: https://youtu.be/GNrdg3PzpJQ
Kuziva kune vanotanga: pfungwa dzekutanga
Mhoro Nyika!
Paunenge uchiwana peji rekutanga reraibhurari, mushandisi achaona musoro unogamuchirwa semuenzaniso mudiki – “Mhoro nyika!”.
Zvinokosha zveJSX system mutauro
JSX isystem programming mutauro, kuwedzera kweinozivikanwa JavaScript. Inosanganisira musanganiswa wemitauro miviri – JA programming uye yakamisikidzwa HTML markup mutauro. Vagadziri vanoishandisa kugadzirisa iyo pfungwa kuratidza React chaizvo kuti iyo mushandisi interface inofanira kutaridzika sei. JSX inogadzira “zvikamu” zveraibhurari.
Chii chinonzi JSX?
Iyo React raibhurari inoomerera kune iyo logic yekuti musimboti wekupa wakanangana neiyo logic yemushandisi wemushandisi: magadzirisirwo ezviitiko, maitiro anochinja mune imwe nguva, uye kuti ruzivo rwunogadzirirwa sei kuratidzwa. Iyo JS raibhurari inogona kushandiswa pasina yayo system mutauro, asi nhamba huru yevagadziri vanoiona yakakosha nekuda kwekujeka kwayo uye kongiri pakushanda nemushandisi interface inogadzirwa kubva kuJavaScript kodhi. Uye zvakare, iyo yekuwedzera inoita kuti zvive nyore kuReact kuburitsa nguva isiriyo uye zviziviso zvekukanganisa.
Kuumbwa kwemazwi mumutauro wehurongwa
JSX inokutendera kuti ushandise chero yakanyatso nyorwa JavaScript mataurirwo mukati akamonereka braces mukuita.
JSX iri zvakare chirevo Kana iyo sosi kodhi yaiswa bytecoded, chero JSX kutaura kunoshanduka kuita yakajairwa JS basa rekufona rinotarisa chikamu cheJavaScript. Kubva pane izvi zvinogona kunzwisiswa kuti iyo yekuwedzera sisitimu yemutauro wepamutemo wepurogiramu inogona kushandiswa mukati meiyo kana bhuku uye kwenguva.
JSX iZvinhu Zvinhu zvinomiririrwa nekuwedzera zvinonzi React elements. Ivo vanojekesa mhedzisiro iyo mugadziri anoda kuona pachiratidziro. Raibhurari inoziva zvinhu izvi uye inozvishandisa mukugadzira nekuchengetedza iyo Gwaro Object Model.
Detail rendering
Ruzivo ndiwo akawanda madiki ekuvaka anoumba React zvirongwa.
Details ndiwo mufananidzo uyo mugadziri anoda kuona mukupedzisira pane monitor. Kuenzaniswa neGwaro Chinhu Muenzanisi zvinhu, zvinhu zveraibhurari zviri nyore uye hazvitore zviwanikwa zvakawanda. Zvinhu zvinoumba zvikamu zvezvikamu.
Zvikamu uye Props
Zvikamu zvinoita kuti zvikwanise kupatsanura UI kuita zvikamu zvakazvimirira, zviri nyore kushanda pazviri zvakasiyana. Vanogona kusanganiswa uye kushandiswa kakawanda. Kune chikamu chikuru, kushanda kwezvikamu kwakafanana nekushanda kweJavaScript programming language pachayo. Ivo vanotora ruzivo rwekupinza, rwunodaidzwa kuti props, uye vanodzosera React zvinhu zvinoratidza iyo yekuvandudza modhi iyo mugadziri anoda kuona pane yekutarisa.
Mhando dzezvikamu: zvinoshanda uye kirasi
Zviri nyore kureva chikamu cheraibhurari sechishandiso.
Zvikamu zvinogona zvakare kumiririrwa muES6 kirasi fomati.
Inonakidza! Raibhurari yeReact inotsanangura aya marudzi maviri ezvikamu zvakafanana.
props
Props zvinhu zvisingachinjike zvinoverengwa-chete. Naizvozvo, chikamu hachifanirwe kunyora chero chinhu kumapuropu acho, zvisinei kuti ndecherudzii.
Nyika uye kutenderera kwehupenyu
Kutanga, ngationei kuti tingashandisa sei zvakanaka nyika pabasa. Pane zvinhu zvitatu zvakakosha zvekuziva nezve chikamu chechimiro:
- Usashandura mamiriro acho zvakananga, shandisa iyo setState nzira. Rangarira kuti iyo chete nzvimbo yaunogona kushandura iyo nyika zvakananga ndiye muvaki.
- Zvigadziriso zvehurumende zvinogona kunge zvisiri kuenderana.
- Kuyerera kweruzivo kune gwara rimwe. Mukuvakwa kwechikamu, hapana mumwe wavo anoziva kana nyika yakapihwa chimwe chikamu. Izvo hazvina basa kuti ichi kana icho chakazvimirira chinoshanda chinhu chakaumbwa sei – uchishandisa inoshanda kana kupatsanura chishandiso. Izvi zvinonzi “downstream” data flow. Nyika inogara ichitsanangurwa kune chimwe chinhu, uye mubatanidzwa wezvimiro zveiyi nyika unogona kungokanganisa zvikamu zviri “pazasi” muhurongwa hwehumambo.
Kazhinji, iyo nyika inonzi “yenzvimbo”, “yemukati”, kana yakavanzika. Inongoonekwa kune iyo inoshanda chinhu pachayo uye isingaonekwe kune zvimwe zvikamu zveReact. Muzvirongwa zveraibhurari, ingave chinhu chakazvimirira chinoshanda chakapihwa imwe nyika kana kwete kusimudzira kwemukati kwechikamu ichi, chinogona kuchinja nekufamba kwenguva. Zvinonakidzawo kuti mubasa iwe unogona kusanganisa zvikamu uye uye pasina nyika.
Chiitiko chekuongorora
Maitiro ekuparadzanisa zviitiko muReact zvikamu zvakafanana nekubata zviitiko mugwaro chinhu modhi zvinhu. Nekudaro, pane akati wandei maficha anoasiyanisa kubva kune mumwe nemumwe:
- Zviitiko muraibhurari yeJavaScript zvinodaidzwa nenzira yakasiyana neyakajairwa.
- Uchishandisa iyo System Yakawedzerwa Chirongwa Mutauro, mugadziri anopfuudza subroutine semubati wechiitiko pane tambo.
Conditional kupa zvinhu
Raibhurari yeJavaScript inoita kuti zvikwanise kutyora pfungwa dzekugadzira zvinhu kuita zvikamu zvakazvimirira. Ivo vanogona kuratidzwa kuratidzwa kwakajairwa kana kuvanzwa, zvinoenderana nemamiriro api avakapihwa panguva ino. Conditional kupa zvinhu kunoshanda pamusimboti mumwechete seane conditional mataurirwo akavakirwa paJavaScript programming language. Dzimwe nguva zvinoitika kuti raibhurari inoda tsananguro yekuti nyika inokanganisa sei kuvanza kana kupa kwezvimwe zvinhu. Pano zvine musoro kushandisa chirevo cheJS mubatsiri kana mataurirwo akafanana ne.
Kuchinja Zvikamu
React raibhurari zvinhu zvinogona kuwedzerwa kune akasiyana. Iyi imhinduro inoshanda apo imwe mamiriro inoratidza kana chimwe chikamu chechikamu chinofanira kudhirowa, kana kuti hachina musoro, nepo chikamu chasara chinoramba chisina kuchinjika.
Lists uye Keys
Ichi chikamu chinosanganisira zvinhu zvakawanda:
- Kudhirowa zvinhu zvakawanda . Mushandisi anogona kugadzira seti yezvimiro uye kuinyudza mumutauro wehurongwa hwemutauro uchishandisa curly braces.
- Elementary list yezvinhu . Kazhinji, vashandisi nevagadziri vanogadzirisa zvinyorwa zvakananga mukati mechikamu chechikamu.
Keys
Kiyi muraibhurari yeReact JavaScript inoreva chishandiso chakasarudzika chinofanira kuiswa kana uchigadzira rondedzero yezvikamu. Makiyi anobatsira JavaScript raibhurari kuona kuti ndezvipi zvinhu zvakagadziridzwa, zvakawedzerwa, kana kubviswa. Izvo zvakakosha kuti uzvimake kuitira kuti React inogona kuwiriranisa zvikamu zveiyo data yemaitiro mushure mekunge imwe nguva yadarika.
Mafomu
Muraibhurari yeJS, mitauro yakamisikidzwa yemitauro inoshanda zvakati siyanei pane zvikamu zvegwaro chinhu modhi, nekuti maumbirwo emhando pakutanga ane chakavanzika.
Managed Items
Mumutauro wakamisikidzwa wemarkup, mafomu senge ekuisa, sarudza, textarea anowanzo kuchengetedza iwo ega mamiriro uye anoavandudza kana mugadziri apinza ruzivo rutsva. React.js state inogara ichitsanangura kukosha kwenzvimbo dzekuisa mune inogadziriswa kugadzira chinhu. Kunyangwe izvi zvichiratidza kuti mushandisi anofanirwa kunyora zvishoma kupfuura iyo yekutanga yakapihwa kodhi, ikozvino zvinogoneka kupfuudza kukosha uku kune zvimwe zvikamu zvemushandisi interface.
Kusimuka kwehurumende
State lifting ndiyo yakamisikidzwa template iyo mugadziri wese anofanirwa kuziva nezvayo uye kugona kushandisa mukuita basa. Kuishandisa kunobvisa maitiro akaoma uye kazhinji asingabatsiri ehurumende.
Sei zvakakosha kudzora kusimuka kwehurumende?
Kusimudza nyika kusvika padanho rezvakapfuura zvezvikamu izvo zvinoda izvo zvinodikanwa kuti zvinhu zvese zvitore chikamu muhurumende. Nzvimbo yakagadzikana yehurumende ichaita kuti zvive nyore kuigovera pakati pezvikamu zvose zvinovimba nayo.
Composition vs Nhaka
React.js inosanganisira yakasimba yekuumbwa modhi, saka zvinokurudzirwa kushandisa maitiro ekuvaka akazara kubva kune zvikamu panzvimbo yenhaka kushandisazve kodhi yakanyorwa kare pakati pezvinhu. Nekudaro, maprops uye kugona kugadzira imwe chete kuumbwa kubva kuchikamu chechikamu, inopa mugadziri nekuchinjika kunodiwa kugadzira iyo goko uye maitiro echinhu mune chaiyo uye yakachengeteka nzira.
Chiyeuchidzo! Zvikamu zvezvikamu zvinogona kutora mapuropu asina hukama, kusanganisira zvikamu zvekutanga zvinoumba maraibhurari kana mabasa.
Muchiitiko chekuti iwe unofanirwa kushandisa inotaridzika-yemahara basa rekushanda nezvikamu kechipiri kana kechitatu, dhonza kunze mune yakaparadzana JS module. Ifambise muchikamu uye shandisa iyo yakagadzirwa basa pasina kumwe kuwedzera. React kana Vue kana Angular, chii chekusarudza: https://youtu.be/Nm8GpLCAgwk
React.js Misimboti
Ihwo huzivi hwese hweJavaScript raibhurari yakavanzwa muReact gwara. Zvinoita sekuti iyi yakareba uye haina kukosha kukuru, zvisinei, vashandisi vazhinji vanoti mushure mekuverenga zvese zvakawira munzvimbo. Zvinyorwa ndezvekare, asi zvichiri zvakakosha uye zvakakosha –
https://ru.reactjs.org/docs/thinking-in-react.html . React js tutorial https://ru.reactjs.org/tutorial/tutorial.html
Kushanda kweraibhurari yeReact.js
Uchishandisa raibhurari yeJavaScript, mushandisi anowana mukana wekubhadhara kutarisisa kwake kwese zvakananga kuhurongwa hwekuvandudza UI uye zvikamu zvechishandiso, zvishoma pane zvese zviri kukanganiswa nekuumbwa uye zvinokwanisika kukanganisa kwekodhi yakanyorwa. Raibhurari inobvumidza iwe kugadzira zvirongwa nekukurumidza, zvinoita kuti zvive nyore kugadzirisa uye kugadzirisa zvikamu uye maitiro eiyo purojekiti yese. Nekudaro, React.js ine zvinhu zvinokonzeresa kutaurirana mune yepasirese network, UI, chirongwa chekutonga nyika uye kugona kugadzirisa dzimwe nyaya dzakaoma. Iyo raibhurari zvakare ine zvinotevera zvinoshanda maficha:
- Practicality . React.js inowanikwa mune minified format. Iyi compact package haidi kurongeka zvakajeka. Inotosanganisira kodhi yekupatsanura iyo inoderedza nguva inotora kuvhura browser vhezheni yesaiti, sezvo iyi sarudzo inodzivirira zvikamu kubva pakupa panguva imwe chete.
- Pumped ecosystem uye kutevedzera . Nhamba huru yezvishandiso inowanikwa muraibhurari, inotsigirwa nedzimwe nzvimbo, iyo inobvumira mushandisi kugadzira mapurogiramu matsva akaoma kune chero chinangwa.
- Full functionality . Kubatsira kukuru kweraibhurari yeJavaScript ndeyokuti zvose zvitsva zvepuratifomu zvinosangana nezvinodiwa zvekare, saka unogona kushandisa zvose zvekare uye shanduro yakagadziridzwa, yose inotsigirwa uye yakakosha kusvika nhasi. Mavhezheni akamboburitswa haashande mushure mekuvandudzwa.
Kushandisa kunoshanda
Pa peji guru reraibhurari, mune mirairo yevashandisi, kune akati wandei emifananidzo mienzaniso yekushandisa React mukuita. Unogona kuzvigadzirisa nemaoko uye edza kuzvimhanyisa. Kunyangwe iwe uri mushandisi mutsva uye usinganzwisise musimboti uye pfungwa yeraibhurari, gadzirisa iyo kodhi kune yaunofarira uye ona mhedzisiro.
Kushanda kwekushandisa kweReact kana uchinyora kutengesa marobhoti muJavaScript
Zvakakosha kuziva kuti mugadziri haagadziri JS, asi anonyora zvinyorwa (zvinyorwa). saka, uchishandisa raibhurari, mugadziri anogona kunyora kodeti kune inotevera yekutengesa marobhoti inoshandiswa pakutengesa zvinangwa, uye zvakare ramba uchigadzira chitarisiko chayo zvichienderana nepuratifomu iyi. Muchokwadi, robhoti rekutengesa rekutengesa iri zvakare application, iyo yakawanda nhamba iri kugadzirwa uchishandisa React.js. Nekudaro, mamwe mabasa uye chikamu chemukati chebhoti chichiri kufanirwa kuitwa kune mamwe mawebhusaiti anopa maturusi akakodzera izvi.
GitHub uye React.js
GitHub ipuratifomu inobata ese mavhezheni emapurojekiti. Mushandisi anobatanidza kubata, anoenda nenzira yekunyoresa pane yepamutemo GitHub webhusaiti, uye obva agadzira online repository kwaanotamisa mafaera ese kubva kuGit.
Git ndiyo inonyanya kufarirwa uye yakakosha purojekiti yekudzora sevhisi nhasi, uye GitHub iri kure kodhi repository.
Reference! Vaya vashandisi chete vakagamuchira chinongedzo chakakodzera nemvumo vanogona kuwana kugadzirisa uye kurodha mafaera.
Zvinyorwa
Ese matutorials uye zvigadziriso zvemazuva ano zvine chekuita neJavaScript raibhurari zvazvino neazvino update. Vagadziri vanounganidzawo uye vanotumira kuti vaverenge mavhezheni ekare ezvinyorwa, zvakatumirwa pane imwe peji reraibhurari. Naizvozvo, zvichave nyore kune vanotanga kugona hunyanzvi hwekutarisira saiti: zvese zvekare uye zvitsva zvinhu – zvese zviri pano, kuwana mahara kune wese munhu.
Cherechedza! Usakanganwa kuverenga zvinyorwa. Zvirinani tarisa – zvatove zvakawanda izvo zvaiita sezvisinganzwisisike zvichawira munzvimbo.
Raibhurari yeReact inzvimbo yakakurumbira uye yakakodzera nhasi. Kuita kwayo kwakasiyana-siyana kunobvumira vanogadzira kugadzira mapurojekiti emhando yepamusoro uye munguva shoma. Uye zvakare, kuziva chikuva uye kuve nehunyanzvi hwekuishandisa kunoita kuti nyanzvi iwedzere kudiwa mumusika wevashandi.