Sida Loogu Gudbiyo Xogta Components-ka Adigoo Isticmaalaya Props
Props waa maxay?
Props waa hab React u isticmaasho si xog looga gudbiyo hal component una gudubto component kale. Props waa shayyo ama objects loo gudbiyo components-ka React, iyagoo u oggolaanaya inay noqdaan kuwo is-dhexgala oo ka jawaaba xogaha iyo isbeddelka isticmaalaha. Props waxay muhiim u yihiin sameynta components reusable ah oo isla markaana xog kala duwan kala shaqeeya.
How to Pass Data to Components via Props |
Sida Props Loogu Gudbiyo Components-ka
Si aad props ugu gudbiso component, waxaad u isticmaashaa qaabka JSX. Props-ka waxaa lagu qoraa sida astaamo (attributes) loogu daro component-ka, waxaana loo gudbiyaa sida shay (object) oo ku jira component-ka la doortay.
javascript
function Greeting(props) {
return <h1>Hello, {props.name}!</h1>;
}
function App() {
return (
<div>
<Greeting name="Ahmed" />
<Greeting name="Hodan" />
<Greeting name="Zahra" />
</div>
);
}
Faa'iidooyinka Isticmaalka Props
Reusability (Dib u Isticmaal): Components-ka React waxay noqdaan kuwa dib loo isticmaali karo markay ka shaqeyn karaan xog kala duwan iyagoo isticmaalaya props. Tani waxay yareynaysaa koodka oo waxay kordhisaa wax-soo-saarka.
Isdhexgalka Xogaha: Props waxay u fududeeyaan components-ka inay xog kala duwan ka helaan component waalid (parent component) ama qayb kale oo React ah, taasoo suurtagal ka dhigaysa in xogta laga wadaago qaybaha kala duwan ee app-kaaga.
Kalagoynta Shaqada: Props waxay sahlaan in la kala saaro shaqada qeybaha kala duwan ee app-kaaga, sidaa darteed waxaa suurtagal ah inaad ka shaqeyso qaybaha kala duwan si ka madax bannaan.
Gunaanad
Props waa mid ka mid ah qaybaha ugu muhiimsan ee React, iyadoo u suurtagalinaysa developers-ka inay dhisaan components kala duwan oo si fudud oo hufan ugu shaqeynaya xogaha. Iyadoo la adeegsanayo props, waxaad abuuri kartaa components-ka isdhexgala, oo xogta ka wadaaga, taasoo fududeynaysa sameynta codsiyo (applications) awood badan oo ballaaran.