Lifting State Up - U guurinta state ka mid ah components kala duwan
![]() |
Maxay tahay Lifting State Up?
Lifting State Up waa hab React.js loogu guuriyo state component hoose (child) kuna soo saaro component sare (parent). Tani waxay muhiim u tahay marka components kala duwan u baahan yihiin inay helaan xog isku mid ah. Halkii mid kasta oo ka mid ah components uu yeelan lahaa state u gaar ah, xogta waxaa lagu kaydiyaa component-ka sare si loo hubiyo in la wadaago isla xogta.
Tusaale ahaan, aan ka fikirno laba component oo kala ah TemperatureInput iyo TemperatureConverter. Labaduba waxay u baahan yihiin inay xog ka helaan midba midka kale. Haddii mid ka mid ah uu beddelo qiimaha, waa in kan kale isaguna cusboonaysiiyaa.
Sidee Lifting State Up u shaqeeyaa?
Waxaan u baahan nahay inaan xogta ka saarno component-ka hoose oo aan u gudbino component-ka sare (parent), kadibna component-hoose wuxuu xogta ka helayaa props, halkii uu lahaa state u gaar ah.
Tusaale Code Lifting State Up
Aan tusaale ku qaadano laba input oo kala ah Celsius iyo Fahrenheit oo isku xiran:
- TemperatureConverter waa component-ka sare, wuxuuna hayaa state-ka temperature.
- TemperatureInput waa component-hoose, wuxuu helayaa props si uu u isticmaalo xogta.
- Markii user-ku wax ku qoro input, xogta waxa lagu kaydiyaa TemperatureConverter, kadibna dib ayaa loogu soo dirayaa labada input.
- Tani waxay xaqiijinaysaa in labadooduba la wadaagaan xog isku mid ah.
Faa'iidooyinka Lifting State Up
✅ Wuxuu ka hortagayaa xog isku dhex yaacda.
✅ Wuxuu fududeeyaa wadaaga xogta components badan.
✅ Wuxuu hagaajiyaa sida React u shaqeyso iyo sida components iskula shaqeeyaan.
✅ Wuxuu yareeyaa code aan loo baahnayn oo la dhigi lahaa components badan.
Gabagabadii iyo gunaanudkii
Lifting State Up waa hab muhiim u ah React.js si ay components kala duwan si sax ah ugu wadaagaan state. Halkii xog laga hayn lahaa meelo kala duwan, waxaa wanaagsan in lagu hayo component sare si loo hagaajiyo maareynta xogta (state management). Tani waxay sahleysaa in components-ku noqdaan kuwa la maareyn karo si fudud oo nadiif ah.