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/thinking-in-react.md
+23-21Lines changed: 23 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -248,40 +248,41 @@ td {
248
248
249
249
</DeepDive>
250
250
251
-
## Step 4: Identify where your state should live {/*step-4-identify-where-your-state-should-live*/}
251
+
## الخطوة 4: حدد أين تضع الحالات {/*step-4-identify-where-your-state-should-live*/}
252
252
253
-
After identifying your app’s minimal state data, you need to identify which component is responsible for changing this state, or *owns* the state. Remember: React uses one-way data flow, passing data down the component hierarchy from parent to child component. It may not be immediately clear which component should own what state. This can be challenging if you’re new to this concept, but you can figure it out by following these steps!
253
+
بعد أن حدد القدر الأدنى من بيانات الحالات اللازمة، عليك الأن أن تحدد أي المكونات مسءول عن تغيير كلٌّ من هذه الحالات، أو *يملك* تلك الحالة. تذكر أن React يستخدم سيل البيانات في اتجاه واحد، وهو تمرير البيانات من المكون الأب لمكون تابع له في التسلسل الشجري. قد لا يبدو واضحا من الوهلة الأولى أي مكون يجب أن يملك تلك "الحالة" ويكون مسؤولا عنها. ربما يكون هذا تحديا لك إن كان هذا المفهوم جديدا عليك،لكن ستتمكن من إيجاد الإجابة باتباع الخطوات التالية!
254
254
255
-
For each piece of state in your application:
255
+
لكل حالة على حدة في تطبيقك:
256
256
257
-
1.Identify *every* component that renders something based on that state.
258
-
2.Find their closest common parent component--a component above them all in the hierarchy.
259
-
3.Decide where the state should live:
260
-
1.Often, you can put the state directly into their common parent.
261
-
2.You can also put the state into some component above their common parent.
262
-
3.If you can't find a component where it makes sense to own the state, create a new component solely for holding the state and add it somewhere in the hierarchy above the common parent component.
257
+
1.حدد *جميع* المكونات التي تعرض أي شيء له علاقة بهذه الحالة.
258
+
2.حدد السلف الأقرب المشترك بينهم؛ مكون يكون أعلى منهم جميعا في التسلسل الشجري.
259
+
3.حدد أين يجب أن تتمركز الحالة:
260
+
1.عادة، يمكنك وضع الحالة مباشرة في سلفهم المشترك.
261
+
2.يمكنك أيضا أن تضع الحالة في مكون أعلى من السلف المشترك.
262
+
3.إن لم يكن بإمكانك تحديد مكون حيث يبدو من المنطقي وضع الحالة فيه، قم بعمل مكون جديد خصيصا لحفظ تلك الحالة، وقم بوضعه في مكان ما في التسلسل الشجري يسبق سلفهم المشترك.
263
263
264
-
In the previous step, you found two pieces of state in this application: the search input text, and the value of the checkbox. In this example, they always appear together, so it makes sense to put them into the same place.
264
+
في الخطوة السابقة، وجدت حالتين في هذا التطبيق: نص البحث المكتوب، وحالة مربع الاختيار. في هذا المثال، يظهران دائما معا، فمن المنطقي وضعهم معا في نفس المكان.
265
265
266
266
Now let's run through our strategy for them:
267
+
حسنا، لنقوم باختبار طريقتنا عليهم:
267
268
268
-
1.**Identify components that use state:**
269
-
*`ProductTable`needs to filter the product list based on that state (search text and checkbox value).
270
-
*`SearchBar`needs to display that state (search text and checkbox value).
271
-
1.**Find their common parent:**The first parent component both components share is`FilterableProductTable`.
272
-
2.**Decide where the state lives**: We'll keep the filter text and checked state values in`FilterableProductTable`.
269
+
1.**حدد المكونات التي تستخدم الحالة:**
270
+
*مكون (جدول المنتجات) `ProductTable`يحتاج الحالة ليقوم بتصفية قائمة المنتجات (نص البحث وحالة مربع الاختيار).
271
+
*مكون (خانة البحث) `SearchBar`يقوم بعرض الحالة نفسها (نص البحث).
272
+
1.**حدد لهم سلفا مشتركا:**السلف المشترك للمكونين هو`FilterableProductTable`.
273
+
2.**حدد أين تضع الحالة**: سنضع نص البحث وحالة مربع الاختيار في المكون`FilterableProductTable`.
273
274
274
-
So the state values will live in`FilterableProductTable`.
275
+
إذا، فقيم الحالات ستكون محفوظة لدى المكون`FilterableProductTable`.
275
276
276
-
Add state to the component with the [`useState()` Hook.](/reference/react/useState) Hooks are special functions that let you "hook into" React. Add two state variables at the top of `FilterableProductTable`and specify their initial state:
277
+
أضف الحالات للمكون باستخدام [خطاف `useState()`.](/reference/react/useState)الخطافات (Hooks) عبارة عن دوال خاصة تسمح لك أن "تربط" مكوناتك بنظام React. أضف متغيرا لكل حالة في بداية الكود الخاص بالمكون `FilterableProductTable`وحدد حالتهم الأولية:
ثم مرر المتغير `filterText`و`inStockOnly`للمكونين`ProductTable`و`SearchBar`كخاصية ضمن خصائص كلا منهما:
285
286
286
287
```js
287
288
<div>
@@ -296,6 +297,7 @@ Then, pass `filterText` and `inStockOnly` to `ProductTable` and `SearchBar` as p
296
297
```
297
298
298
299
You can start seeing how your application will behave. Edit the `filterText` initial value from `useState('')` to `useState('fruit')` in the sandbox code below. You'll see both the search input text and the table update:
300
+
قد يبدو واضحا لك من الآن كيف سيبدو سلوك تطبيقك. قم بتعديل قيمة `filterText` الأولية من `useState('')` إلى `useState('fruit')` في الكود التالي داخل الـsandbox المدرج. سترى نتيجة التعديل على كلا من محتوى خانة البحث وجدول المنتجات:
299
301
300
302
<Sandpack>
301
303
@@ -437,15 +439,15 @@ td {
437
439
438
440
</Sandpack>
439
441
440
-
Notice that editing the form doesn't work yet. There is a console error in the sandbox above explaining why:
442
+
لاحظ أنك لو عدلت مباشرة على نموذج البحث فلن يحدث شيء. هناك رسالة خطأ في الـsandbox أعلاه تخبرك لماذا:
441
443
442
444
<ConsoleBlock level="error">
443
445
444
446
You provided a \`value\` prop to a form field without an \`onChange\` handler. This will render a read-only field.
445
447
446
448
</ConsoleBlock>
447
449
448
-
In the sandbox above,`ProductTable`and`SearchBar`read the`filterText`and`inStockOnly`props to render the table, the input, and the checkbox. For example, here is how`SearchBar`populates the input value:
450
+
في الـsandbox أعلاه؛ المكونان`ProductTable`و`SearchBar`يقرآن الخصائص`filterText`و`inStockOnly`لعرض الجدول، مربع البحث، ومربع الاختيار. إليك مثلا كيف يقوم المكون`SearchBar`بكتابة محتوى مربع البحث:
449
451
450
452
```js {1,6}
451
453
functionSearchBar({ filterText, inStockOnly }) {
@@ -457,7 +459,7 @@ function SearchBar({ filterText, inStockOnly }) {
457
459
placeholder="Search..."/>
458
460
```
459
461
460
-
However, you haven't added any code to respond to the user actions like typing yet. This will be your final step.
462
+
برغم ذلك، فأنت لم تقم بعد بكتابة أي كود للتجاوب مع تفاعلات المستخدم (كالكتابة). هذه ستكون خطوتك الأخيرة.
461
463
462
464
463
465
## Step 5: Add inverse data flow {/*step-5-add-inverse-data-flow*/}
0 commit comments