You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/learn/managing-state.md
+35-34Lines changed: 35 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,31 @@
1
1
---
2
-
title: Managing State
2
+
title: إدارة الحالة
3
3
---
4
4
5
5
<Intro>
6
6
7
-
As your application grows, it helps to be more intentional about how your state is organized and how the data flows between your components. Redundant or duplicate state is a common source of bugs. In this chapter, you'll learn how to structure your state well, how to keep your state update logic maintainable, and how to share state between distant components.
7
+
مع نمو تطبيقك، من المفيد كونك أكثر حرصا بشأن أن تكون حالتك منظمة وأن تكون البيانات متدفقة خلال مكوناتك. تكرار أو نسخ الحالة هو مصدر شائع للأخطاء. في هذا الفصل، سوف تتعلم كيفية تهيئة حالتك جيدا، كيفية الحفاظ على منطق تحديث حالتك مصانا، وكيفية مشاركة الحالة بين المكونات المتباعدة.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearnisChapter={true}>
12
12
13
-
*[How to think about UI changes as state changes](/learn/reacting-to-input-with-state)
14
-
*[How to structure state well](/learn/choosing-the-state-structure)
15
-
*[How to "lift state up" to share it between components](/learn/sharing-state-between-components)
16
-
*[How to control whether the state gets preserved or reset](/learn/preserving-and-resetting-state)
17
-
*[How to consolidate complex state logic in a function](/learn/extracting-state-logic-into-a-reducer)
18
-
*[How to pass information without "prop drilling"](/learn/passing-data-deeply-with-context)
19
-
*[How to scale state management as your app grows](/learn/scaling-up-with-reducer-and-context)
13
+
*[كيفية التفكير في تغييرات واجهة المستخدم كتغيرات في الحالة](/learn/reacting-to-input-with-state)
14
+
*[كيفية هيكلة الحالة جيدا](/learn/choosing-the-state-structure)
15
+
*[كيفية "رفع الحالة لمستوى أعلى" لمشاكارتها بين المكونات](/learn/sharing-state-between-components)
16
+
*[كيفية التحكم في ما إذا تم حفظ الحالة أم إعادة تعيينها](/learn/preserving-and-resetting-state)
17
+
*[كيفية ترسيخ منطق حالة معقد داخل دالة](/learn/extracting-state-logic-into-a-reducer)
18
+
*[كيفية تمرير معلومات بدون "تسرب الخصائص"](/learn/passing-data-deeply-with-context)
19
+
*[كيفية توسيع إدارة الحالة مع نمو تطبيقك](/learn/scaling-up-with-reducer-and-context)
20
20
21
21
</YouWillLearn>
22
22
23
-
## Reacting to input with state {/*reacting-to-input-with-state*/}
23
+
## الاستجابة للمدخلات باستخدام الحالة {/*reacting-to-input-with-state*/}
24
24
25
-
With React, you won't modify the UI from code directly. For example, you won't write commands like "disable the button", "enable the button", "show the success message", etc. Instead, you will describe the UI you want to see for the different visual states of your component ("initial state", "typing state", "success state"), and then trigger the state changes in response to user input. This is similar to how designers think about UI.
25
+
باستخدام React، لن تستطيع تعديل واجهة المستخدم عن طريق الكود مباشرة. على سبيل المثال، لن تكتب أوامر مثل "عطل الزر"، "فعل الزر"، إلخ. بدلا عن ذلك، سوف تصف واجهة المستخدم التي تريد أن ترها للحالات المرئية من مكوناتك ("حالة ابتدائية"، "حالة كتابية"، "حالة ناجحة")، ومن بعدها تنشيط تغيرات الحالة بناءا على مدخل المستخدم. هذا مشابه لتصور المصممين عن واجهة المستخدم.
26
+
27
+
هنا نموذج اختبار صمم باستخدام React. لاحظ كيف يستخدم متغير الحالة `status` لكي يحدد ما إذا سيفعل أم سيعطل زر الإرسال، وما إذا ستظهر رسالة نجاح بدلا عن ذلك.
26
28
27
-
Here is a quiz form built using React. Note how it uses the `status` state variable to determine whether to enable or disable the submit button, and whether to show the success message instead.
28
29
29
30
<Sandpack>
30
31
@@ -37,7 +38,7 @@ export default function Form() {
37
38
const [status, setStatus] =useState('typing');
38
39
39
40
if (status ==='success') {
40
-
return<h1>That's right!</h1>
41
+
return<h1>هذا صحيح!</h1>
41
42
}
42
43
43
44
asyncfunctionhandleSubmit(e) {
@@ -58,9 +59,9 @@ export default function Form() {
58
59
59
60
return (
60
61
<>
61
-
<h2>City quiz</h2>
62
+
<h2>اختبار المدينة</h2>
62
63
<p>
63
-
In which city is there a billboard that turns air into drinkable water?
64
+
في أي مدينة يوجد لوحة إعلانية تقوم بتحويل الهواء إلى مياه صالحة للشرب؟
64
65
</p>
65
66
<form onSubmit={handleSubmit}>
66
67
<textarea
@@ -73,7 +74,7 @@ export default function Form() {
73
74
answer.length===0||
74
75
status ==='submitting'
75
76
}>
76
-
Submit
77
+
أرسل
77
78
</button>
78
79
{error !==null&&
79
80
<p className="Error">
@@ -86,12 +87,12 @@ export default function Form() {
86
87
}
87
88
88
89
functionsubmitForm(answer) {
89
-
// Pretend it's hitting the network.
90
+
//محاكاة للتواصل باستخدام الشبكة
90
91
returnnewPromise((resolve, reject) => {
91
92
setTimeout(() => {
92
-
let shouldError =answer.toLowerCase() !=='lima'
93
+
let shouldError =answer.toLowerCase() !=='lima'
93
94
if (shouldError) {
94
-
reject(newError('Good guess but a wrong answer. Try again!'));
95
+
reject(newError('توقع جيد ولكن إجابة خاطئة. حاول مرة أخرى!'));
95
96
} else {
96
97
resolve();
97
98
}
@@ -108,15 +109,15 @@ function submitForm(answer) {
Read **[Reacting to Input with State](/learn/reacting-to-input-with-state)** to learn how to approach interactions with a state-driven mindset.
112
+
اقرأ**[الاستجابة للمدخلات باستخدام الحالة](/learn/reacting-to-input-with-state)**لكي تتعلم كيفية الوصول لتعاملات مع عقلية معتمدة على الحالة.
112
113
113
114
</LearnMore>
114
115
115
-
## Choosing the state structure {/*choosing-the-state-structure*/}
116
+
## اختيار هيكل الحالة {/*choosing-the-state-structure*/}
116
117
117
-
Structuring state well can make a difference between a component that is pleasant to modify and debug, and one that is a constant source of bugs. The most important principle is that state shouldn't contain redundant or duplicated information. If there's unnecessary state, it's easy to forget to update it, and introduce bugs!
118
+
هيكلة الحالة جيدا يستطيع أن يصنع فارقا بين مكوّن قابل للإصلاح والتصحيح، وآخر يمثل مصدرا ثابتا للأخطاء. القاعدة الأكثر أهمية هي أنه لا يجب للحالة أن تحتوي على بيانات مكررة أو منسوخة. لو وجدت حالة غير ضرورية، فمن السهل نسيان تحديثها، وحدوث الأخطاء.
118
119
119
-
For example, this form has a **redundant** `fullName`state variable:
120
+
على سبيل المثال، هذا نموذج يتضمن متغير الحالة `fullName`**مكرر**:
120
121
121
122
<Sandpack>
122
123
@@ -140,23 +141,23 @@ export default function Form() {
0 commit comments